Skip to content

Commit 221a5f8

Browse files
committed
Changed Events system on Target -> now using UnityEvents
1 parent c991c75 commit 221a5f8

8 files changed

Lines changed: 64 additions & 13 deletions

File tree

41.4 KB
Binary file not shown.

Testie/Assets/Scenes/CrosshairTargetTest.unity.meta

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Testie/Assets/main.unity

-1.02 KB
Binary file not shown.

Testie/Assets/seyahdoo/controlls.meta

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
using System.Collections;
2+
using System.Collections.Generic;
3+
using UnityEngine;
4+
5+
namespace seyahdoo.controlls
6+
{
7+
8+
public class SuperSimpleMouseCameraRotator : MonoBehaviour
9+
{
10+
11+
void Update()
12+
{
13+
14+
transform.localEulerAngles += new Vector3(-Input.GetAxis("Mouse Y"), Input.GetAxis("Mouse X"), 0);
15+
16+
}
17+
18+
}
19+
20+
}

Testie/Assets/seyahdoo/controlls/SuperSimpleMouseCameraRotator.cs.meta

Lines changed: 12 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Testie/Assets/seyahdoo/crosshair/Target.cs

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
///seyahdoo.crosshair.Crosshair
1717

1818
using UnityEngine;
19+
using UnityEngine.Events;
1920

2021
namespace seyahdoo.crosshair
2122
{
@@ -46,9 +47,10 @@ public bool HasFocus
4647

4748
/// <summary>
4849
/// object just get focused event
49-
/// Usage: target.FocusOnEvent += MethodToSubscribe;
50+
/// Usage: target.FocusOffEvent.AddListener(MethodName);
51+
5052
/// </summary>
51-
public event VoidDelegate FocusOnEvent;
53+
public UnityEvent FocusOnEvent;
5254

5355
/// <summary>
5456
/// Override me
@@ -57,17 +59,16 @@ virtual protected void FocusOn() { }
5759

5860
/// <summary>
5961
/// object just get unfocused event
60-
/// Usage: target.FocusOffEvent += MethodToSubscribe;
62+
/// Usage: target.FocusOffEvent.AddListener(MethodName);
6163
/// </summary>
62-
public event VoidDelegate FocusOffEvent;
63-
64+
public UnityEvent FocusOffEvent;
65+
6466
/// <summary>
6567
/// Override me
6668
/// </summary>
6769
virtual protected void FocusOff() { }
6870

69-
[System.Obsolete("Do not use setFocus method. It's internal. It is not ment to be used publicly")]
70-
internal void setFocus(bool value)
71+
public void setFocus(bool value)
7172
{
7273
//Nothing to change? Cool.
7374
if (_hasFocus == value) return;
@@ -82,16 +83,16 @@ internal void setFocus(bool value)
8283
FocusOn();
8384

8485
//external events
85-
if (FocusOnEvent != null)
86-
FocusOnEvent();
86+
FocusOnEvent.Invoke();
87+
8788
}else
8889
{
8990
//internal event
9091
FocusOff();
9192

9293
//external events
93-
if (FocusOffEvent != null)
94-
FocusOffEvent();
94+
FocusOffEvent.Invoke();
95+
9596
}
9697

9798
}

Testie/Assets/seyahdoo/crosshair/examples/ColorChangingCube.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,9 @@ void Awake()
2222
m = GetComponent<MeshRenderer>().material;
2323
target = GetComponent<Target>();
2424

25-
target.FocusOnEvent += ColorBlue;
26-
target.FocusOffEvent += ColorRed;
25+
target.FocusOnEvent.AddListener(ColorBlue);
26+
target.FocusOffEvent.AddListener(ColorRed);
27+
2728
}
2829

2930
void ColorBlue()

0 commit comments

Comments
 (0)