agrego highscore

parent 6247ae16
No preview for this file type
......@@ -70,6 +70,7 @@
<Compile Include="Assets\CodeMonkey\Utils\World_Sprite.cs" />
<Compile Include="Assets\CodeMonkey\Utils\World_Bar.cs" />
<Compile Include="Assets\CodeMonkey\Utils\UtilsClass.cs" />
<Compile Include="Assets\Scripts\SoundManager.cs" />
<Compile Include="Assets\CodeMonkey\MonoBehaviours\PositionRendererSorter.cs" />
<Compile Include="Assets\Scripts\Loader.cs" />
<Compile Include="Assets\Scripts\Snake.cs" />
......@@ -85,7 +86,7 @@
<Compile Include="Assets\CodeMonkey\Utils\UI_BarMultiple.cs" />
<Compile Include="Assets\CodeMonkey\CMDebug.cs" />
<Compile Include="Assets\CodeMonkey\Utils\FunctionPeriodic.cs" />
<Compile Include="Assets\Scripts\SoundManager.cs" />
<Compile Include="Assets\Scripts\Score.cs" />
</ItemGroup>
<ItemGroup>
<None Include="Assets\CodeMonkey\README.txt" />
......
......@@ -9,7 +9,7 @@
unitycodemonkey.com
--------------------------------------------------
*/
//#define SOUND_MANAGER // Has Sound_Manager in project
//#define CURSOR_MANAGER // Has Cursor_Manager in project
......@@ -18,12 +18,14 @@ using UnityEngine;
using UnityEngine.UI;
using UnityEngine.EventSystems;
namespace CodeMonkey.Utils {
namespace CodeMonkey.Utils
{
/*
* Button in the UI
* */
public class Button_UI : MonoBehaviour, IPointerEnterHandler, IPointerExitHandler, IPointerClickHandler, IPointerDownHandler, IPointerUpHandler {
public class Button_UI : MonoBehaviour, IPointerEnterHandler, IPointerExitHandler, IPointerClickHandler, IPointerDownHandler, IPointerUpHandler
{
public Action ClickFunc = null;
public Action MouseRightClickFunc = null;
......@@ -39,10 +41,10 @@ namespace CodeMonkey.Utils {
public Action MouseUpdate = null;
public Action<PointerEventData> OnPointerClickFunc;
public enum HoverBehaviour {
public enum HoverBehaviour
{
Custom,
Change_Color,
Change_Color_Auto,
Change_Image,
Change_SetActive,
}
......@@ -59,7 +61,7 @@ namespace CodeMonkey.Utils {
private bool mouseOver;
private float mouseOverPerSecFuncTimer;
private Action internalOnPointerEnterFunc = null, internalOnPointerExitFunc = null, internalOnPointerClickFunc = null;
private Action internalOnPointerEnterFunc, internalOnPointerExitFunc, internalOnPointerClickFunc;
#if SOUND_MANAGER
public Sound_Manager.Sound mouseOverSound, mouseClickSound;
......@@ -69,30 +71,33 @@ namespace CodeMonkey.Utils {
#endif
public virtual void OnPointerEnter(PointerEventData eventData) {
public virtual void OnPointerEnter(PointerEventData eventData)
{
if (internalOnPointerEnterFunc != null) internalOnPointerEnterFunc();
if (hoverBehaviour_Move) transform.GetComponent<RectTransform>().anchoredPosition = posEnter;
if (hoverBehaviour_Move) transform.localPosition = posEnter;
if (hoverBehaviourFunc_Enter != null) hoverBehaviourFunc_Enter();
if (MouseOverOnceFunc != null) MouseOverOnceFunc();
if (MouseOverOnceTooltipFunc != null) MouseOverOnceTooltipFunc();
mouseOver = true;
mouseOverPerSecFuncTimer = 0f;
}
public virtual void OnPointerExit(PointerEventData eventData) {
public virtual void OnPointerExit(PointerEventData eventData)
{
if (internalOnPointerExitFunc != null) internalOnPointerExitFunc();
if (hoverBehaviour_Move) transform.GetComponent<RectTransform>().anchoredPosition = posExit;
if (hoverBehaviour_Move) transform.localPosition = posExit;
if (hoverBehaviourFunc_Exit != null) hoverBehaviourFunc_Exit();
if (MouseOutOnceFunc != null) MouseOutOnceFunc();
if (MouseOutOnceTooltipFunc != null) MouseOutOnceTooltipFunc();
mouseOver = false;
}
public virtual void OnPointerClick(PointerEventData eventData) {
public virtual void OnPointerClick(PointerEventData eventData)
{
if (internalOnPointerClickFunc != null) internalOnPointerClickFunc();
if (OnPointerClickFunc != null) OnPointerClickFunc(eventData);
if (eventData.button == PointerEventData.InputButton.Left) {
if (triggerMouseOutFuncOnClick) {
if (eventData.button == PointerEventData.InputButton.Left)
{
if (triggerMouseOutFuncOnClick)
{
OnPointerExit(eventData);
}
if (ClickFunc != null) ClickFunc();
......@@ -102,28 +107,31 @@ namespace CodeMonkey.Utils {
if (eventData.button == PointerEventData.InputButton.Middle)
if (MouseMiddleClickFunc != null) MouseMiddleClickFunc();
}
public void Manual_OnPointerExit() {
public void Manual_OnPointerExit()
{
OnPointerExit(null);
}
public bool IsMouseOver() {
public bool IsMouseOver()
{
return mouseOver;
}
public void OnPointerDown(PointerEventData eventData) {
public void OnPointerDown(PointerEventData eventData)
{
if (MouseDownOnceFunc != null) MouseDownOnceFunc();
}
public void OnPointerUp(PointerEventData eventData) {
public void OnPointerUp(PointerEventData eventData)
{
if (MouseUpFunc != null) MouseUpFunc();
}
private void Update() {
if (mouseOver) {
void Update()
{
if (mouseOver)
{
if (MouseOverFunc != null) MouseOverFunc();
mouseOverPerSecFuncTimer -= Time.unscaledDeltaTime;
if (mouseOverPerSecFuncTimer <= 0) {
if (mouseOverPerSecFuncTimer <= 0)
{
mouseOverPerSecFuncTimer += 1f;
if (MouseOverPerSecFunc != null) MouseOverPerSecFunc();
}
......@@ -131,10 +139,10 @@ namespace CodeMonkey.Utils {
if (MouseUpdate != null) MouseUpdate();
}
private void Awake() {
posExit = transform.GetComponent<RectTransform>().anchoredPosition;
posEnter = transform.GetComponent<RectTransform>().anchoredPosition + hoverBehaviour_Move_Amount;
void Awake()
{
posExit = transform.localPosition;
posEnter = (Vector2)transform.localPosition + hoverBehaviour_Move_Amount;
SetHoverBehaviourType(hoverBehaviourType);
#if SOUND_MANAGER
......@@ -149,39 +157,26 @@ namespace CodeMonkey.Utils {
internalOnPointerExitFunc += () => { if (cursorMouseOut != CursorManager.CursorType.None) CursorManager.SetCursor(cursorMouseOut); };
#endif
}
public void SetHoverBehaviourType(HoverBehaviour hoverBehaviourType) {
public void SetHoverBehaviourType(HoverBehaviour hoverBehaviourType)
{
this.hoverBehaviourType = hoverBehaviourType;
switch (hoverBehaviourType) {
case HoverBehaviour.Change_Color:
hoverBehaviourFunc_Enter = delegate () { hoverBehaviour_Image.color = hoverBehaviour_Color_Enter; };
hoverBehaviourFunc_Exit = delegate () { hoverBehaviour_Image.color = hoverBehaviour_Color_Exit; };
break;
case HoverBehaviour.Change_Image:
hoverBehaviourFunc_Enter = delegate () { hoverBehaviour_Image.sprite = hoverBehaviour_Sprite_Enter; };
hoverBehaviourFunc_Exit = delegate () { hoverBehaviour_Image.sprite = hoverBehaviour_Sprite_Exit; };
break;
case HoverBehaviour.Change_SetActive:
hoverBehaviourFunc_Enter = delegate () { hoverBehaviour_Image.gameObject.SetActive(true); };
hoverBehaviourFunc_Exit = delegate () { hoverBehaviour_Image.gameObject.SetActive(false); };
break;
case HoverBehaviour.Change_Color_Auto:
Color color = hoverBehaviour_Image.color;
if (color.r >= 1f) color.r = .9f;
if (color.g >= 1f) color.g = .9f;
if (color.b >= 1f) color.b = .9f;
Color colorOver = color * 1.3f; // Over color lighter
hoverBehaviourFunc_Enter = delegate () { hoverBehaviour_Image.color = colorOver; };
hoverBehaviourFunc_Exit = delegate () { hoverBehaviour_Image.color = color; };
break;
switch (hoverBehaviourType)
{
case HoverBehaviour.Change_Color:
hoverBehaviourFunc_Enter = delegate () { hoverBehaviour_Image.color = hoverBehaviour_Color_Enter; };
hoverBehaviourFunc_Exit = delegate () { hoverBehaviour_Image.color = hoverBehaviour_Color_Exit; };
break;
case HoverBehaviour.Change_Image:
hoverBehaviourFunc_Enter = delegate () { hoverBehaviour_Image.sprite = hoverBehaviour_Sprite_Enter; };
hoverBehaviourFunc_Exit = delegate () { hoverBehaviour_Image.sprite = hoverBehaviour_Sprite_Exit; };
break;
case HoverBehaviour.Change_SetActive:
hoverBehaviourFunc_Enter = delegate () { hoverBehaviour_Image.gameObject.SetActive(true); };
hoverBehaviourFunc_Exit = delegate () { hoverBehaviour_Image.gameObject.SetActive(false); };
break;
}
}
public void RefreshHoverBehaviourType() {
SetHoverBehaviourType(hoverBehaviourType);
}
......@@ -194,28 +189,35 @@ namespace CodeMonkey.Utils {
* Class for temporarily intercepting a button action
* Useful for Tutorial disabling specific buttons
* */
public class InterceptActionHandler {
public class InterceptActionHandler
{
private Action removeInterceptFunc;
public InterceptActionHandler(Action removeInterceptFunc) {
public InterceptActionHandler(Action removeInterceptFunc)
{
this.removeInterceptFunc = removeInterceptFunc;
}
public void RemoveIntercept() {
public void RemoveIntercept()
{
removeInterceptFunc();
}
}
public InterceptActionHandler InterceptActionClick(Func<bool> testPassthroughFunc) {
public InterceptActionHandler InterceptActionClick(Func<bool> testPassthroughFunc)
{
return InterceptAction("ClickFunc", testPassthroughFunc);
}
public InterceptActionHandler InterceptAction(string fieldName, Func<bool> testPassthroughFunc) {
public InterceptActionHandler InterceptAction(string fieldName, Func<bool> testPassthroughFunc)
{
return InterceptAction(GetType().GetField(fieldName), testPassthroughFunc);
}
public InterceptActionHandler InterceptAction(System.Reflection.FieldInfo fieldInfo, Func<bool> testPassthroughFunc) {
public InterceptActionHandler InterceptAction(System.Reflection.FieldInfo fieldInfo, Func<bool> testPassthroughFunc)
{
Action backFunc = fieldInfo.GetValue(this) as Action;
InterceptActionHandler interceptActionHandler = new InterceptActionHandler(() => fieldInfo.SetValue(this, backFunc));
fieldInfo.SetValue(this, (Action)delegate () {
if (testPassthroughFunc()) {
if (testPassthroughFunc())
{
// Passthrough
interceptActionHandler.RemoveIntercept();
backFunc();
......
......@@ -214,6 +214,85 @@ CanvasRenderer:
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 46289084}
m_CullTransparentMesh: 1
--- !u!1 &285610985
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 285610986}
- component: {fileID: 285610988}
- component: {fileID: 285610987}
m_Layer: 0
m_Name: scoreText
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!224 &285610986
RectTransform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 285610985}
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 1129460274}
m_RootOrder: 2
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0.5, y: 0.5}
m_AnchorMax: {x: 0.5, y: 0.5}
m_AnchoredPosition: {x: 4, y: 115}
m_SizeDelta: {x: 0, y: 0}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!114 &285610987
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 285610985}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 5f7201a12d95ffc409449d95f23cf332, type: 3}
m_Name:
m_EditorClassIdentifier:
m_Material: {fileID: 0}
m_Color: {r: 1, g: 1, b: 1, a: 1}
m_RaycastTarget: 1
m_RaycastPadding: {x: 0, y: 0, z: 0, w: 0}
m_Maskable: 1
m_OnCullStateChanged:
m_PersistentCalls:
m_Calls: []
m_FontData:
m_Font: {fileID: 10102, guid: 0000000000000000e000000000000000, type: 0}
m_FontSize: 53
m_FontStyle: 1
m_BestFit: 0
m_MinSize: 10
m_MaxSize: 59
m_Alignment: 4
m_AlignByGeometry: 0
m_RichText: 1
m_HorizontalOverflow: 1
m_VerticalOverflow: 1
m_LineSpacing: 1
m_Text: 100
--- !u!222 &285610988
CanvasRenderer:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 285610985}
m_CullTransparentMesh: 1
--- !u!1 &309951112
GameObject:
m_ObjectHideFlags: 0
......@@ -554,6 +633,7 @@ RectTransform:
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children:
- {fileID: 1829641497}
- {fileID: 1498371643}
m_Father: {fileID: 1397380294}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
......@@ -906,6 +986,9 @@ RectTransform:
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children:
- {fileID: 1035974223}
- {fileID: 2092106728}
- {fileID: 285610986}
- {fileID: 1300597585}
m_Father: {fileID: 1397380294}
m_RootOrder: 1
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
......@@ -1085,6 +1168,85 @@ Transform:
m_Father: {fileID: 818425990}
m_RootOrder: 4
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &1300597584
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 1300597585}
- component: {fileID: 1300597587}
- component: {fileID: 1300597586}
m_Layer: 0
m_Name: highscoreText
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!224 &1300597585
RectTransform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1300597584}
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 1129460274}
m_RootOrder: 3
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0.5, y: 0.5}
m_AnchorMax: {x: 0.5, y: 0.5}
m_AnchoredPosition: {x: 5, y: 159}
m_SizeDelta: {x: 0, y: 0}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!114 &1300597586
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1300597584}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 5f7201a12d95ffc409449d95f23cf332, type: 3}
m_Name:
m_EditorClassIdentifier:
m_Material: {fileID: 0}
m_Color: {r: 1, g: 1, b: 1, a: 1}
m_RaycastTarget: 1
m_RaycastPadding: {x: 0, y: 0, z: 0, w: 0}
m_Maskable: 1
m_OnCullStateChanged:
m_PersistentCalls:
m_Calls: []
m_FontData:
m_Font: {fileID: 10102, guid: 0000000000000000e000000000000000, type: 0}
m_FontSize: 25
m_FontStyle: 1
m_BestFit: 0
m_MinSize: 10
m_MaxSize: 55
m_Alignment: 4
m_AlignByGeometry: 0
m_RichText: 1
m_HorizontalOverflow: 1
m_VerticalOverflow: 1
m_LineSpacing: 1
m_Text: HIGHSCORE 100
--- !u!222 &1300597587
CanvasRenderer:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1300597584}
m_CullTransparentMesh: 1
--- !u!1 &1318889150
GameObject:
m_ObjectHideFlags: 0
......@@ -1269,6 +1431,103 @@ Canvas:
m_SortingLayerID: 0
m_SortingOrder: 0
m_TargetDisplay: 0
--- !u!1 &1498371642
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 1498371643}
- component: {fileID: 1498371646}
- component: {fileID: 1498371645}
- component: {fileID: 1498371644}
m_Layer: 0
m_Name: highScoreText
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!224 &1498371643
RectTransform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1498371642}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 759955952}
m_RootOrder: 1
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 1, y: 1}
m_AnchorMax: {x: 1, y: 1}
m_AnchoredPosition: {x: 583, y: 303}
m_SizeDelta: {x: 0, y: 0}
m_Pivot: {x: 1, y: 1}
--- !u!114 &1498371644
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1498371642}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: e19747de3f5aca642ab2be37e372fb86, type: 3}
m_Name:
m_EditorClassIdentifier:
m_EffectColor: {r: 0, g: 0, b: 0, a: 0.5}
m_EffectDistance: {x: 1, y: -1}
m_UseGraphicAlpha: 1
--- !u!114 &1498371645
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1498371642}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 5f7201a12d95ffc409449d95f23cf332, type: 3}
m_Name:
m_EditorClassIdentifier:
m_Material: {fileID: 0}
m_Color: {r: 0.6603774, g: 0.6603774, b: 0.6603774, a: 1}
m_RaycastTarget: 1
m_RaycastPadding: {x: 0, y: 0, z: 0, w: 0}
m_Maskable: 1
m_OnCullStateChanged:
m_PersistentCalls:
m_Calls: []
m_FontData:
m_Font: {fileID: 10102, guid: 0000000000000000e000000000000000, type: 0}
m_FontSize: 26
m_FontStyle: 1
m_BestFit: 0
m_MinSize: 0
m_MaxSize: 71
m_Alignment: 2
m_AlignByGeometry: 0
m_RichText: 1
m_HorizontalOverflow: 1
m_VerticalOverflow: 1
m_LineSpacing: 1
m_Text: 'HIGHSCORE
100'
--- !u!222 &1498371646
CanvasRenderer:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1498371642}
m_CullTransparentMesh: 0
--- !u!1 &1634059632
GameObject:
m_ObjectHideFlags: 0
......@@ -1628,7 +1887,7 @@ CanvasRenderer:
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1829641496}
m_CullTransparentMesh: 1
m_CullTransparentMesh: 0
--- !u!1 &1927639557
GameObject:
m_ObjectHideFlags: 0
......@@ -1858,3 +2117,82 @@ CanvasRenderer:
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 2041563744}
m_CullTransparentMesh: 1
--- !u!1 &2092106727
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 2092106728}
- component: {fileID: 2092106730}
- component: {fileID: 2092106729}
m_Layer: 0
m_Name: newHighscoreText
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!224 &2092106728
RectTransform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 2092106727}
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 1129460274}
m_RootOrder: 1
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0.5, y: 0.5}