public override void BaseGUI()
        {
            GUILayout.Space(5);
            GUILayout.BeginHorizontal();
            GUILayout.Space(5);
            animatorController = ObjectField <RuntimeAnimatorController>(ContentProperties.Animator, animatorController, true);
            if (animatorController != null)
            {
                clips = animatorController.animationClips;
            }
            GUILayout.Space(5);
            GUILayout.EndHorizontal();
            GUILayout.Space(5);

            IncreaseIndentLevel();
            for (int i = 0, length = instance.GetLength(); i < length; i++)
            {
                BeginBox();
                AnimationEventProperty animationEventProperty = instance.GetProperty(i);
                bool          foldout = propertiesFoldout[i];
                string        name    = animationEventProperty.GetAnimationName().AddSpaces();
                AnimationClip clip    = null;
                if (animatorController != null && clips != null)
                {
                    for (int c = 0, c_length = clips.Length; c < c_length; c++)
                    {
                        AnimationClip _clip = clips[c];
                        if (_clip.name == animationEventProperty.GetAnimationName())
                        {
                            clip = _clip;
                            break;
                        }
                    }
                }

                Rect animationRemoveButtonRect = GUILayoutUtility.GetRect(0, 0);
                animationRemoveButtonRect.x      = animationRemoveButtonRect.width + 5;
                animationRemoveButtonRect.y     += 1;
                animationRemoveButtonRect.width  = 16.5f;
                animationRemoveButtonRect.height = 16.5f;
                if (GUI.Button(animationRemoveButtonRect, GUIContent.none, GUI.skin.GetStyle("OL Minus")))
                {
                    properties.DeleteArrayElementAtIndex(i);
                    propertiesFoldout.RemoveAt(i);
                    eventsFoldout.Remove(i);
                    break;
                }

                foldout = EditorGUILayout.Foldout(foldout, name, true);
                if (foldout)
                {
                    GUILayout.Space(3);
                    if (animatorController != null && clips != null)
                    {
                        GUILayout.BeginHorizontal();
                        animationEventProperty.SetAnimationName(EditorGUILayout.TextField(ContentProperties.AnimationName, animationEventProperty.GetAnimationName()));
                        if (ListButton())
                        {
                            GenericMenu menu = new GenericMenu();
                            for (int c = 0, c_length = clips.Length; c < c_length; c++)
                            {
                                AnimationClip _clip       = clips[c];
                                string        sendMessage = i + "," + _clip.name;
                                menu.AddItem(new GUIContent(_clip.name), _clip.name == animationEventProperty.GetAnimationName(), (_object) =>
                                {
                                    string message        = (string)_object as string;
                                    string[] parseMessage = message.Split(',');
                                    int index             = int.Parse(parseMessage[0]);
                                    AnimationEventProperty _animationEventProperty = instance.GetProperty(index);
                                    _animationEventProperty.SetAnimationName(parseMessage[1]);
                                    instance.SetProperty(index, _animationEventProperty);
                                }, sendMessage);
                            }
                            menu.ShowAsContext();
                        }
                        GUILayout.EndHorizontal();
                    }
                    else
                    {
                        animationEventProperty.SetAnimationName(EditorGUILayout.TextField(ContentProperties.AnimationName, animationEventProperty.GetAnimationName()));
                    }

                    AnimationEventProperty.EventProperty[] eventProperties = animationEventProperty.GetEventProperties();
                    SerializedProperty serializedEventProperties           = properties.GetArrayElementAtIndex(i).FindPropertyRelative("eventProperties");
                    for (int j = 0, _length = eventProperties.Length; j < _length; j++)
                    {
                        if (!eventsFoldout.ContainsKey(i) || eventsFoldout[i].Count == 0 || j >= eventsFoldout[i].Count)
                        {
                            break;
                        }

                        BeginSubBox();
                        bool eventFoldout = eventsFoldout[i][j];

                        Rect eventRemoveButtonRect = GUILayoutUtility.GetRect(0, 0);
                        eventRemoveButtonRect.x      = eventRemoveButtonRect.width + 15;
                        eventRemoveButtonRect.y     += 1;
                        eventRemoveButtonRect.width  = 16.5f;
                        eventRemoveButtonRect.height = 16.5f;
                        if (GUI.Button(eventRemoveButtonRect, GUIContent.none, GUI.skin.GetStyle("OL Minus")))
                        {
                            serializedEventProperties.DeleteArrayElementAtIndex(j);
                            eventsFoldout[i].RemoveAt(j);
                            break;
                        }

                        eventFoldout = EditorGUILayout.Foldout(eventFoldout, "Event " + (j + 1), true);
                        if (eventFoldout)
                        {
                            GUILayout.Space(3);
                            AnimationEventProperty.EventProperty eventProperty = eventProperties[j];
                            if (animatorController != null && clips != null && clip != null)
                            {
                                eventProperty.SetAnimationTime(EditorGUILayout.Slider(ContentProperties.AnimationTime, eventProperty.GetAnimationTime(), 0, clip.length));
                            }
                            else
                            {
                                eventProperty.SetAnimationTime(EditorGUILayout.FloatField(ContentProperties.AnimationTime, eventProperty.GetAnimationTime()));
                            }

                            GUILayout.Space(10);
                            GUILayout.Label(ContentProperties.SoundEffect, UEditorStyles.SectionHeaderLabel);
                            GUILayout.Space(5);
                            eventProperty.SetSoundEffect(ObjectField <AudioClip>(ContentProperties.SoundEffect, eventProperty.GetSoundEffect(), false));

                            GUILayout.Space(10);
                            GUILayout.Label(ContentProperties.CameraShake, UEditorStyles.SectionHeaderLabel);
                            GUILayout.Space(5);
                            ShakeCamera.ShakeProperties shakeProperties = eventProperty.GetShakeProperties();
                            shakeProperties.SetTarget((ShakeCamera.ShakeEvent.Target)EditorGUILayout.EnumPopup("Target", shakeProperties.GetTarget()));
                            EditorGUI.BeginDisabledGroup(shakeProperties.GetTarget() == ShakeCamera.ShakeEvent.Target.None);
                            shakeProperties.SetAmplitude(EditorGUILayout.FloatField("Amplitude", shakeProperties.GetAmplitude()));
                            shakeProperties.SetFrequency(EditorGUILayout.FloatField("Frequency", shakeProperties.GetFrequency()));
                            shakeProperties.SetDuration(EditorGUILayout.FloatField("Duration", shakeProperties.GetDuration()));
                            shakeProperties.SetBlendOverLifetime(EditorGUILayout.CurveField("Blend Over Life time", shakeProperties.GetBlendOverLifetime()));
                            EditorGUI.EndDisabledGroup();
                            eventProperty.SetShakeProperties(shakeProperties);
                            eventProperties[j] = eventProperty;
                            GUILayout.Space(3);
                        }
                        eventsFoldout[i][j] = eventFoldout;
                        EndSubBox();
                    }
                    animationEventProperty.SetEventProperties(eventProperties);

                    GUILayout.Space(3);

                    GUILayout.BeginHorizontal();
                    GUILayout.FlexibleSpace();

                    bool clipContains = (animatorController != null && clips != null && clip != null && (clip.events != null && clip.events.Length > 0));

                    if (GUILayout.Button(" Add Event ", clipContains ? "ButtonLeft" : "Button"))
                    {
                        serializedEventProperties.arraySize++;
                        eventsFoldout[i].Add(false);
                        break;
                    }

                    if (clipContains)
                    {
                        if (GUILayout.Button(new GUIContent(" Parse Event ", "Current clip contains event.\nPress \"Parse events\" to read and add this events here."), "ButtonRight"))
                        {
                            AnimationEvent[] unityAnimationEvents = clip.events;
                            for (int e = 0, e_length = unityAnimationEvents.Length; e < e_length; e++)
                            {
                                serializedEventProperties.arraySize++;
                                eventsFoldout[i].Add(false);
                                AnimationEvent     unityAnimationEvent = unityAnimationEvents[e];
                                SerializedProperty animationTime       = serializedEventProperties.GetArrayElementAtIndex(serializedEventProperties.arraySize - 1).FindPropertyRelative("animationTime");
                                SerializedProperty soundEffect         = serializedEventProperties.GetArrayElementAtIndex(serializedEventProperties.arraySize - 1).FindPropertyRelative("soundEffect");
                                soundEffect.objectReferenceValue = unityAnimationEvent.objectReferenceParameter;
                                animationTime.floatValue         = unityAnimationEvent.time;
                            }
                            break;
                        }
                    }
                    GUILayout.EndHorizontal();
                    GUILayout.Space(3);
                }
                propertiesFoldout[i] = foldout;
                instance.SetProperty(i, animationEventProperty);
                EndBox();
            }
            DecreaseIndentLevel();

            GUILayout.Space(3);

            if (instance.GetLength() == 0)
            {
                UEditorHelpBoxMessages.Tip("Properties is empty!", "Add new properties.");
            }

            GUILayout.BeginHorizontal();
            GUILayout.FlexibleSpace();
            if (GUILayout.Button("Add Animation", "ButtonLeft", GUILayout.Width(120)))
            {
                properties.arraySize++;
                properties.GetArrayElementAtIndex(properties.arraySize - 1).FindPropertyRelative("animationName").stringValue = "Empty " + properties.arraySize;
                properties.GetArrayElementAtIndex(properties.arraySize - 1).FindPropertyRelative("eventProperties").arraySize = 0;
                propertiesFoldout.Add(false);
                eventsFoldout.Add(properties.arraySize - 1, new List <bool>());
            }

            if (GUILayout.Button("Clear All Animation", "ButtonRight", GUILayout.Width(120)))
            {
                if (UDisplayDialogs.Confirmation(string.Format("Are you sure want clear camera shake properites:[{0}]", properties.arraySize)))
                {
                    properties.arraySize = 0;
                    propertiesFoldout.Clear();
                    eventsFoldout.Clear();
                }
            }
            GUILayout.FlexibleSpace();
            GUILayout.EndHorizontal();
        }
Ejemplo n.º 2
0
        private static void WeaponIDsListGUI()
        {
            if (weaponIDs != null && weaponIDs.Count > 0)
            {
                GUILayout.BeginVertical(EditorStyles.helpBox);
                GUILayout.Space(3);

                for (int i = 0; i < weaponIDs.Count; i++)
                {
                    if (i >= weaponIDs.Count)
                    {
                        break;
                    }

                    Object _weaponID = weaponIDs[i];
                    if (_weaponID == null)
                    {
                        OnEnable();
                        continue;
                    }

                    GUILayout.BeginHorizontal();
                    GUILayout.Space(3);
                    GUILayout.Label(_weaponID.name, EditorStyles.boldLabel);

                    GUI.color = new Color32(70, 150, 255, 255);
                    if (GUILayout.Button("Open", "ButtonLeft", GUILayout.Width(70)))
                    {
                        Selection.activeObject = _weaponID;
                    }

#if UNITY_EDITOR_OSX
                    EditorGUI.BeginDisabledGroup(true);
#endif

                    GUI.color = new Color32(70, 220, 70, 255);
                    if (GUILayout.Button("Duplicate", "ButtonMid", GUILayout.Width(70)))
                    {
                        string path = AssetDatabase.GetAssetPath(_weaponID);
                        string name = _weaponID.name;
                        path = path.Replace(_weaponID.name + ".asset", "");
                        AssetDatabase.CopyAsset(AssetDatabase.GetAssetPath(_weaponID), path + name + ".asset");
                        AssetDatabase.Refresh();
                        OnEnable();
                    }

#if UNITY_EDITOR_OSX
                    EditorGUI.EndDisabledGroup();
#endif

                    GUI.color = new Color32(255, 55, 55, 255);
                    if (GUILayout.Button("Delete", "ButtonRight", GUILayout.Width(70)))
                    {
                        if (UDisplayDialogs.Confirmation("Are you really want to delete \"" + _weaponID.name + "\" asset?"))
                        {
                            string path = AssetDatabase.GetAssetPath(_weaponID);
                            AssetDatabase.DeleteAsset(path);
                            AssetDatabase.Refresh();
                            OnEnable();
                            break;
                        }
                    }
                    GUI.color = Color.white;
                    GUILayout.Space(3);
                    GUILayout.EndHorizontal();

                    if (weaponIDs.Count > 1 && i < weaponIDs.Count - 1)
                    {
                        GUILayout.Space(3);
                        UEditor.HorizontalLine();
                        GUILayout.Space(3);
                    }
                    else
                    {
                        GUILayout.Space(3);
                    }
                }
                GUILayout.Space(3);
                GUILayout.EndVertical();
            }
            else
            {
                UEditorHelpBoxMessages.Message("WeaponID's not found...\n" + "Create new property or reload properties", MessageType.Warning);
            }

            GUILayout.Space(5);

            GUILayout.BeginHorizontal();
            GUILayout.FlexibleSpace();
            if (GUILayout.Button(" Refresh Assets ", GUILayout.Width(105.5f)))
            {
                weaponIDs = UEditorInternal.FindAssetsByType <WeaponID>();
            }
            GUILayout.Space(8);
            GUILayout.EndHorizontal();
        }
Ejemplo n.º 3
0
        public override void BaseGUI()
        {
            if (instance == null)
            {
                return;
            }

            for (int i = 0; i < instance.GetLength(); i++)
            {
                BeginBox();
                IncreaseIndentLevel();
                ClimbstepProperty  property           = instance.GetProperty(i);
                SerializedProperty serializedProperty = properties.GetArrayElementAtIndex(i);
                string             propertyName       = "New Property " + (i + 1);
                if (property.GetPhysicMaterial() != null)
                {
                    propertyName = property.GetPhysicMaterial().name;
                }

                Rect removeButtonRect = GUILayoutUtility.GetRect(0, 0);
                removeButtonRect.x      = removeButtonRect.width + 5;
                removeButtonRect.y     += 1;
                removeButtonRect.width  = 16.5f;
                removeButtonRect.height = 16.5f;
                if (GUI.Button(removeButtonRect, GUIContent.none, GUI.skin.GetStyle("OL Minus")))
                {
                    properties.DeleteArrayElementAtIndex(i);
                    propertiesFoldout.RemoveAt(i);
                    break;
                }

                propertiesFoldout[i] = EditorGUILayout.Foldout(propertiesFoldout[i], propertyName, true);
                if (propertiesFoldout[i])
                {
                    GUILayout.Space(3);
                    GUILayout.Label("Surface", UEditorStyles.SectionHeaderLabel);
                    GUILayout.Space(5);
                    property.SetPhysicMaterial((PhysicMaterial)EditorGUILayout.ObjectField("Physic Material", property.GetPhysicMaterial(), typeof(PhysicMaterial), true));
                    if (property.GetPhysicMaterial() == null)
                    {
                        UEditorHelpBoxMessages.Tip("Add Physic Material for handle surface.", "For create Physic Material press right mouse button Create > Physic Material.", true);
                    }

                    GUILayout.Space(10);
                    GUILayout.Label("Sounds", UEditorStyles.SectionHeaderLabel);
                    GUILayout.Space(5);
                    BeginSubBox();
                    GUILayout.Space(3);
                    climbFoldout = EditorGUILayout.Foldout(climbFoldout, "Climb ounds", true);
                    if (climbFoldout)
                    {
                        if (property.GetSoundsLength() == 0)
                        {
                            UEditorHelpBoxMessages.Tip("Climb sounds is empty!", "Add new climb sound by click on [Add] button.", true);
                        }
                        for (int s = 0; s < property.GetSoundsLength(); s++)
                        {
                            string clipName = property.GetSound(i) != null?property.GetSound(i).name : "Clip " + (i + 1);

                            GUILayout.BeginHorizontal();
                            GUILayout.Space(3);
                            GUILayout.Label(clipName, GUILayout.Width(35));
                            property.SetSound(i, (AudioClip)EditorGUILayout.ObjectField(property.GetSound(i), typeof(AudioClip), true));
                            if (GUILayout.Button("", GUI.skin.GetStyle("OL Minus"), GUILayout.Width(20)))
                            {
                                serializedProperty.FindPropertyRelative("sounds").DeleteArrayElementAtIndex(s);
                            }
                            GUILayout.Space(3);
                            GUILayout.EndHorizontal();
                        }
                        GUILayout.Space(3);
                        GUILayout.BeginHorizontal();
                        GUILayout.FlexibleSpace();
                        if (GUILayout.Button(" Add "))
                        {
                            serializedProperty.FindPropertyRelative("sounds").arraySize++;
                        }
                        GUILayout.EndHorizontal();
                    }
                    GUILayout.Space(3);
                    EndSubBox();

                    GUILayout.Space(3);
                    instance.SetProperty(i, property);
                }
                DecreaseIndentLevel();
                EndBox();
            }

            if (instance.GetLength() == 0)
            {
                UEditorHelpBoxMessages.Tip("Properties is empty!", "Add new properties.");
            }

            GUILayout.BeginHorizontal();
            GUILayout.FlexibleSpace();
            if (GUILayout.Button(" Add Property ", "ButtonLeft", GUILayout.Width(120)))
            {
                properties.arraySize++;
                propertiesFoldout.Add(false);
            }

            if (GUILayout.Button(" Clear All Properties ", "ButtonRight", GUILayout.Width(120)))
            {
                if (UDisplayDialogs.Confirmation("Are you really want to remove all properties from this Climbstep Properties asset?"))
                {
                    properties.ClearArray();
                }
            }
            GUILayout.FlexibleSpace();
            GUILayout.EndHorizontal();
        }