Пример #1
0
    public static void Init()
    {
        _animator      = Services.PlayerMovement.GetComponentInChildren <Animator>();
        _spineAnimator = Services.PlayerMovement.GetComponent <FIMSpace.FSpine.FSpineAnimator>();

        if (_animator == null)
        {
            Logger.Warning("Failed to retrieve animator.");
        }
    }
Пример #2
0
        /// <summary>
        /// Searching for second spine animator in parent, if there is not then transform of this game object is returned
        /// </summary>
        public Transform FindBaseTransform()
        {
            Transform target = transform;

            Transform      p;
            Transform      c       = transform.parent;
            FSpineAnimator mySpine = null;

            if (c != null)
            {
                for (int i = 0; i < 32; i++)
                {
                    p       = c.parent;
                    mySpine = c.GetComponent <FSpineAnimator>();
                    if (mySpine)
                    {
                        break;
                    }
                    c = p;
                    if (p == null)
                    {
                        break;
                    }
                }
            }

            if (mySpine != null)
            {
                if (mySpine.BaseTransform != null)
                {
                    target = mySpine.BaseTransform;
                }
                else
                {
                    target = mySpine.transform;
                }
                if (mySpine.transform != transform)
                {
                    UpdateAsLast = true;
                }
            }

            return(target);
        }
        public override void OnInspectorGUI()
        {
            SpineAnimatorQueuer targetScript = (SpineAnimatorQueuer)target;

            if (targetScript.updateOrder == null)
            {
                targetScript.updateOrder = new List <FSpineAnimator>();
            }

            serializedObject.Update();

            if (!Application.isPlaying)
            {
                EditorGUILayout.HelpBox("Spine Animators will be disabled in playmode but this component will update them in defined update order internally", MessageType.Info);
            }

            Color preC = GUI.color;

            GUI.color = new Color(0.7f, 0.7f, 0.975f, .85f);
            EditorGUILayout.BeginVertical(FGUI_Resources.BGInBoxStyleH); GUI.color = preC;
            EditorGUILayout.BeginVertical(FGUI_Resources.BGInBoxBlankStyle);


            EditorGUIUtility.labelWidth = 150;
            EditorGUILayout.PropertyField(serializedObject.FindProperty("SpineAnimatorsAmount"));
            EditorGUIUtility.labelWidth = 0;
            GUILayout.Space(6);

            EditorGUILayout.BeginHorizontal(FGUI_Resources.BGInBoxStyle);
            EditorGUILayout.LabelField("Define Execution Order", EditorStyles.boldLabel);

            if (GUILayout.Button("+", GUILayout.Width(32)))
            {
                targetScript.updateOrder.Add(null);
                EditorUtility.SetDirty(targetScript);
                serializedObject.Update();
            }

            EditorGUILayout.EndHorizontal();

            GUILayout.Space(4);

            for (int i = 0; i < targetScript.updateOrder.Count; i++)
            {
                GUILayout.Space(6);
                EditorGUILayout.BeginHorizontal();
                FSpineAnimator pre = targetScript.updateOrder[i];

                string title = "[" + (i + 1) + "] ";

                if (pre != null)
                {
                    if (pre._editor_Title != "Spine Animator 2")
                    {
                        title += pre._editor_Title;
                    }

                    GUIContent t = new GUIContent(title);
                    EditorGUILayout.LabelField(t, GUILayout.Width(EditorStyles.label.CalcSize(t).x + 4));
                }

                FSpineAnimator drag = (FSpineAnimator)EditorGUILayout.ObjectField(targetScript.updateOrder[i], typeof(FSpineAnimator), true);

                if (drag != pre)
                {
                    if (!targetScript.updateOrder.Contains(drag))
                    {
                        targetScript.updateOrder[i] = drag;
                        EditorUtility.SetDirty(targetScript);
                        serializedObject.Update();
                    }
                }

                GUILayout.FlexibleSpace();

                EditorGUILayout.BeginVertical();

                int h = 12;
                if (i == 0 || i == targetScript.updateOrder.Count - 1)
                {
                    h = 16;
                }

                if (i > 0)
                {
                    if (GUILayout.Button("▲", FGUI_Resources.ButtonStyle, new GUILayoutOption[2] {
                        GUILayout.Width(22), GUILayout.Height(h)
                    }))
                    {
                        FSpineAnimator toMove = targetScript.updateOrder[i];
                        FSpineAnimator toSwap = targetScript.updateOrder[i - 1];

                        targetScript.updateOrder[i - 1] = toMove;
                        targetScript.updateOrder[i]     = toSwap;

                        EditorUtility.SetDirty(targetScript);
                        serializedObject.Update();
                        serializedObject.ApplyModifiedProperties();
                        return;
                    }
                }

                if (i < targetScript.updateOrder.Count - 1)
                {
                    if (GUILayout.Button("▼", FGUI_Resources.ButtonStyle, new GUILayoutOption[2] {
                        GUILayout.Width(22), GUILayout.Height(h)
                    }))
                    {
                        FSpineAnimator toMove = targetScript.updateOrder[i];
                        FSpineAnimator toSwap = targetScript.updateOrder[i + 1];

                        targetScript.updateOrder[i + 1] = toMove;
                        targetScript.updateOrder[i]     = toSwap;

                        EditorUtility.SetDirty(targetScript);
                        serializedObject.Update();
                        serializedObject.ApplyModifiedProperties();
                        return;
                    }
                }

                EditorGUILayout.EndVertical();

                if (GUILayout.Button("X", FGUI_Resources.ButtonStyle, new GUILayoutOption[2] {
                    GUILayout.Width(22), GUILayout.Height(16)
                }))
                {
                    targetScript.updateOrder.RemoveAt(i);
                    EditorUtility.SetDirty(targetScript);
                    serializedObject.Update();
                    serializedObject.ApplyModifiedProperties();
                    return;
                }

                EditorGUILayout.EndHorizontal();
            }

            GUILayout.Space(2);
            EditorGUILayout.EndVertical();
            EditorGUILayout.EndVertical();
            GUILayout.Space(2);

            serializedObject.ApplyModifiedProperties();
        }