Esempio n. 1
0
        private void Reset()
        {
            // Finds the fisrt parent object with a CanvasMenu component and sets the _fromMenu field to that menu.
            for (Transform parent = transform.parent; parent != null && parent.transform is RectTransform; parent = parent.parent)
            {
                if (parent.TryGetComponent <CanvasMenu>(out CanvasMenu menu))
                {
                    _fromMenu = menu;
                    break;
                }
            }

            // Adds the transition to the button's click event.
            var onClick = GetComponent <Button>().onClick;

            int removeAt = -1;

            for (int i = 0; i < onClick.GetPersistentEventCount(); i++)
            {
                if (onClick.GetPersistentMethodName(i) == nameof(Transition))
                {
                    removeAt = i;
                    break;
                }
            }

            if (removeAt < 0)
            {
                UnityEventTools.AddPersistentListener(GetComponent <Button>().onClick, new UnityAction(Transition));
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Transitions from the <see cref="CanvasMenu"/> to <paramref name="to"/>, records history.
        /// </summary>
        /// <param name="to"></param>
        public void TransitionTo(CanvasMenu to)
        {
            to.RegisterHistoryChange(this);
            to.Open();
            Close();

            Transitioned?.Invoke(this, to);
        }
Esempio n. 3
0
        private void RegisterHistoryChange(CanvasMenu from)
        {
            if (_ignoreHistoryChange)
            {
                _ignoreHistoryChange = false;
                return;
            }

            _previousMenus.Push(from);

            _nextMenus.Clear();
        }
 private void Reset()
 {
     // Finds the fisrt parent object with a CanvasMenu component and sets the _menu field to that menu.
     for (Transform parent = transform.parent; parent != null && parent.transform is RectTransform; parent = parent.parent)
     {
         if (parent.TryGetComponent <CanvasMenu>(out CanvasMenu menu))
         {
             _menu = menu;
             break;
         }
     }
 }
        public override void OnInspectorGUI()
        {
            CanvasMenu targetMenu = (CanvasMenu)target;

            // Open status.
            using (new GUILayout.HorizontalScope())
            {
                EditorGUILayout.PrefixLabel("Open State:");
                Color startContentColor = GUI.contentColor;
                GUI.contentColor = targetMenu.IsOpen ? Color.green : new Color(1, 0.8f, 0);
                GUILayout.Label(targetMenu.IsOpen ? "Open" : "Closed");
                GUI.contentColor = startContentColor;
            }

            GUILayout.Space(8);

            // Transitions.
            EditorGUILayout.PropertyField(serializedObject.FindProperty("_openTransitionType"));
            if (targetMenu.CloseTransitionType == CanvasMenu.TransitionType.Animation)
            {
                EditorGUI.indentLevel++;
                EditorGUILayout.PropertyField(serializedObject.FindProperty("_openTriggerName"));
                EditorGUI.indentLevel--;
            }

            EditorGUILayout.PropertyField(serializedObject.FindProperty("_closeTransitionType"));
            if (targetMenu.CloseTransitionType == CanvasMenu.TransitionType.Animation)
            {
                EditorGUI.indentLevel++;
                EditorGUILayout.PropertyField(serializedObject.FindProperty("_closeTriggerName"));
                EditorGUILayout.PropertyField(serializedObject.FindProperty("_closeStateName"));
                EditorGUI.indentLevel--;
            }


            GUILayout.Space(8);

            // Events.
            EditorGUILayout.PropertyField(serializedObject.FindProperty("_onOpened"));
            EditorGUILayout.PropertyField(serializedObject.FindProperty("_onClosed"));

            // Open close toggles.
            if (MenuManager.CanvasMenus.Count == 0)
            {
                MenuManager.ForcePopulate();
            }

            using (new GUILayout.HorizontalScope())
            {
                if (GUILayout.Button("Toggle " + (targetMenu.IsOpen ? "Closed" : "Open")))
                {
                    if (targetMenu.IsOpen)
                    {
                        targetMenu.CloseImmediate();
                    }
                    else
                    {
                        targetMenu.OpenImmediate();
                    }
                }

                if (GUILayout.Button("Solo Open"))
                {
                    for (int i = MenuManager.CanvasMenus.Count - 1; i >= 0; i--)
                    {
                        if (MenuManager.CanvasMenus[i] == null)
                        {
                            MenuManager.CanvasMenus.RemoveAt(i);
                            continue;
                        }

                        MenuManager.CanvasMenus[i].CloseImmediate();
                    }
                    targetMenu.OpenImmediate();
                }
            }

            serializedObject.ApplyModifiedProperties();
        }