void GUIInspectorView()
        {
            EditorGUILayout.BeginVertical(EditorStyles.helpBox, GUILayout.Width(m_toolbarWidth));
            GUILayout.Label("Inspector View", EditorStyles.boldLabel);

            m_editorScroll = EditorGUILayout.BeginScrollView(m_editorScroll, GUILayout.Width(m_toolbarWidth));
            var previoustarget = m_target;

            m_target = (GameObject)EditorGUILayout.ObjectField(m_target, typeof(GameObject), false);

            // m_target = (RuntimeAnimatorController)EditorGUILayout.ObjectField(m_target, typeof(RuntimeAnimatorController), false);
            if (previoustarget != m_target)
            {
                m_hitboxManager  = null;
                m_Inspector      = null;
                m_SpriteRenderer = null;
                InitHitBoxManager();
                Repaint();
                return;
            }

            GUIRenderInspector();

            EditorGUILayout.EndScrollView();
            EditorGUILayout.EndVertical();
        }
Example #2
0
        public void OnEnable()
        {
            oldBGColor = GUI.backgroundColor;
            oldFGColor = GUI.contentColor;
            if (target == null)
            {
                return;
            }

            m_targetManager     = (HitboxManager)target;
            m_targetObject      = new SerializedObject(target);
            m_SelectedAnimation = m_targetObject.FindProperty(nameof(m_targetManager.m_CurrentAnimation));
            m_SelectedFrame     = m_targetObject.FindProperty(nameof(m_targetManager.m_CurrentFrame));
            m_SelectedCollider  = m_targetObject.FindProperty(nameof(m_targetManager.m_CurrentCollider));
        }
Example #3
0
        private void GUIAddNewAnimationButton(HitboxManager m_Target, SerializedProperty Animations)
        {
            if (GUILayout.Button("Add New Animation"))
            {
                string path = EditorUtility.OpenFilePanel("Select Animation Clip", "", "anim");

                if (!string.IsNullOrEmpty(path))
                {
                    int indexOf = path.IndexOf("Assets/");
                    path = path.Substring(indexOf >= 0 ? indexOf : 0);
                    var loadedClip = AssetDatabase.LoadAssetAtPath <AnimationClip>(path);

                    if (loadedClip == null)
                    {
                        Debug.LogError("HITBOXMANAGER ERROR: Unable to load animation clip at path \"" + path + "\"\n\r Is this this animation located inside your project's assets folder?");
                    }
                    else
                    {
                        Animations.InsertArrayElementAtIndex(Mathf.Max(0, Animations.arraySize - 1));

                        m_targetObject.ApplyModifiedProperties();

                        SerializedProperty HitboxData = Animations.GetArrayElementAtIndex(Animations.arraySize - 1);
                        var clip      = HitboxData.FindPropertyRelative("clip");
                        var framedata = HitboxData.FindPropertyRelative("frameData");

                        clip.objectReferenceValue = loadedClip;
                        for (int i = 0, j = m_Target.GetNumFrames(Animations.arraySize - 1); i < j; i++)
                        {
                            framedata.InsertArrayElementAtIndex(0);
                            framedata.GetArrayElementAtIndex(0).FindPropertyRelative("collider").ClearArray();
                            framedata.GetArrayElementAtIndex(0).FindPropertyRelative("events").ClearArray();
                        }

                        SelectedAnimation = Animations.arraySize - 1;
                        SelectedFrame     = 0;
                        m_targetObject.ApplyModifiedProperties();
                    }
                }
            }
        }
Example #4
0
        private void GUIFrameDataLayout(HitboxManager m_Target, SerializedProperty clip, SerializedProperty framedata, UnityEngine.Object oldclip)
        {
            //New animations need their frame data populated
            if (oldclip != clip.objectReferenceValue && clip.objectReferenceValue != null || framedata.arraySize == 0)
            {
                framedata.ClearArray();
                framedata.arraySize = 0;
                ApplySerializedProperties();
                for (int i = 0, j = m_Target.GetNumFrames(SelectedAnimation); i < j; i++)
                {
                    framedata.InsertArrayElementAtIndex(0);
                }
                ApplySerializedProperties();
            }

            GUILayout.Label("Frame Data", EditorStyles.boldLabel);
            // showFrameData = EditorGUILayout.Foldout(showFrameData, "Frame Data", true);
            // if (showFrameData)
            {
                GUILayout.Label("Frames in clip: " + m_Target.GetNumFrames(SelectedAnimation));
                SelectedFrame = EditorGUILayout.IntSlider(SelectedFrame, 0, Mathf.Max(0, m_Target.GetNumFrames(SelectedAnimation) - 1));

                EditorGUI.indentLevel++;

                if (SelectedFrame < framedata.arraySize)
                {
                    var events = framedata.GetArrayElementAtIndex(SelectedFrame).FindPropertyRelative("events");
                    EditorGUILayout.PropertyField(events, true);

                    // var collider = framedata.GetArrayElementAtIndex(SelectedFrame).FindPropertyRelative("collider");
                }
                else
                {
                    for (int i = framedata.arraySize; i <= SelectedFrame; i++)
                    {
                        framedata.InsertArrayElementAtIndex(i);
                        ApplySerializedProperties();
                    }
                }
            }
        }
        void InitHitBoxManager()
        {
            m_hitboxManager = m_target == null ? null : m_hitboxManager = m_target.GetComponentInChildren <HitboxManager>();

            if (m_hitboxManager == null)
            {
                m_SpriteRenderer = null;
                m_Inspector      = null;
                return;
            }

            // m_character = m_target.GetComponentInChildren<ICharacter>();
            if (m_SpriteRenderer == null)
            {
                m_SpriteRenderer = m_target.GetComponentInChildren <SpriteRenderer>();
            }
            if (m_Inspector == null)
            {
                m_Inspector = (HitBoxManagerInspector)Editor.CreateEditor(m_hitboxManager);
                m_target.GetComponentInChildren <SpriteRenderer>();
            }
        }