public void ShowWindow(SPData sPData, SerializedProperty follower, FollowerSettingsType _followerSettingsType)
    {
        if (Banner == null)
        {
            Banner = new GUIContent((Texture2D)EditorGUIUtility.Load("Assets/ElseForty/Media/Banner.png"));
        }
        windw                = this;
        windw.Follower       = follower;
        windw.SPData         = sPData;
        followerSettingsType = _followerSettingsType;
        if (oldWindw != null)
        {
            oldWindw.Close();
        }
        oldWindw = windw;

        Events();
        SceneView.RepaintAll();
    }
Esempio n. 2
0
    public void DrawFollower(SPData SPData, SerializedProperty follower, Rect rect)
    {
        var followerExpandContent = (follower.FindPropertyRelative("Show").boolValue) ? SplinePlusEditor.Plus : SplinePlusEditor.Minus;

        if (GUI.Button(new Rect(rect.x, rect.y, 20, SplinePlusEditor.ElementHeight), followerExpandContent, GUIStyle.none))
        {
            follower.FindPropertyRelative("Show").boolValue = !follower.FindPropertyRelative("Show").boolValue;
            follower.serializedObject.ApplyModifiedProperties();
        }

        if (!follower.FindPropertyRelative("Show").boolValue)
        {
            EditorGUI.BeginChangeCheck();
            EditorGUI.ObjectField(new Rect(90, rect.y, rect.width - 100, SplinePlusEditor.ElementHeight),
                                  follower.FindPropertyRelative("FollowerGO"), typeof(GameObject), new GUIContent(""));
            if (EditorGUI.EndChangeCheck())
            {
                if (follower.FindPropertyRelative("FollowerGO") != null)
                {
                    follower.FindPropertyRelative("IsActive").boolValue = true;
                }

                follower.serializedObject.ApplyModifiedProperties();
                SPData.SplinePlus.FollowerClass.Follow(SPData);
            }
            var FollowerIsActiveContent = (follower.FindPropertyRelative("IsActive").boolValue) ? SplinePlusEditor.On : SplinePlusEditor.Off;
            if (GUI.Button(new Rect(rect.width, rect.y, 40, SplinePlusEditor.ElementHeight), new GUIContent(FollowerIsActiveContent.image, "Enable/disable follower animation"), GUIStyle.none))
            {
                follower.FindPropertyRelative("IsActive").boolValue = !follower.FindPropertyRelative("IsActive").boolValue;
                follower.serializedObject.ApplyModifiedProperties();

                SPData.SplinePlus.FollowerClass.Follow(SPData);
            }

            if (GUI.Button(new Rect(rect.x + 20, rect.y, 20, SplinePlusEditor.ElementHeight), new GUIContent(SplinePlusEditor.Settings.image, "Follower settings"), GUIStyle.none))
            {
                FollowerSettingsWind wind = (FollowerSettingsWind)EditorWindow.GetWindow(typeof(FollowerSettingsWind), true, "Follower settings", true);
                wind.Show();
                wind.ShowWindow(SPData, follower, FollowerSettingsType.Follower);
            }

            return;
        }


        var FollowerIsActiveContent2 = (follower.FindPropertyRelative("IsActive").boolValue) ? SplinePlusEditor.On : SplinePlusEditor.Off;

        if (GUI.Button(new Rect(rect.width, rect.y, 40, SplinePlusEditor.ElementHeight), new GUIContent(FollowerIsActiveContent2.image, "Enable/disable follower animation"), GUIStyle.none))
        {
            follower.FindPropertyRelative("IsActive").boolValue = !follower.FindPropertyRelative("IsActive").boolValue;
        }

        if (GUI.Button(new Rect(rect.x + 20, rect.y, 20, SplinePlusEditor.ElementHeight), new GUIContent(SplinePlusEditor.Settings.image, "Follower settings"), GUIStyle.none))
        {
            FollowerSettingsWind wind = (FollowerSettingsWind)EditorWindow.GetWindow(typeof(FollowerSettingsWind), true, "Follower settings", true);
            wind.Show();
            wind.ShowWindow(SPData, follower, FollowerSettingsType.Follower);
        }

        EditorGUI.BeginChangeCheck();
        EditorGUI.ObjectField(new Rect(90, rect.y, rect.width - 100, SplinePlusEditor.ElementHeight),
                              follower.FindPropertyRelative("FollowerGO"), typeof(GameObject), new GUIContent(""));
        if (EditorGUI.EndChangeCheck())
        {
            if (follower.FindPropertyRelative("FollowerGO") != null)
            {
                follower.FindPropertyRelative("IsActive").boolValue = true;
            }

            follower.serializedObject.ApplyModifiedProperties();
            SPData.SplinePlus.FollowerClass.Follow(SPData);
        }

        rect.y = rect.y + SplinePlusEditor.ElementHeight + SplinePlusEditor.ElementHeightSpace;

        EditorGUI.BeginChangeCheck();
        var progress = EditorGUI.FloatField(new Rect(rect.x, rect.y, rect.width - 38, SplinePlusEditor.ElementHeight), "Progress", follower.FindPropertyRelative("Progress").floatValue);

        if (EditorGUI.EndChangeCheck())
        {
            var branchDist = SPData.DictBranches[follower.FindPropertyRelative("_BranchKey").intValue].BranchDistance;
            if (progress < 0)
            {
                progress = 0;
            }
            if (progress > branchDist)
            {
                progress = branchDist;
            }

            follower.FindPropertyRelative("Progress").floatValue = progress;
            follower.serializedObject.ApplyModifiedProperties();

            SPData.SplinePlus.FollowerClass.Follow(SPData);
        }

        rect.y = rect.y + SplinePlusEditor.ElementHeight + SplinePlusEditor.ElementHeightSpace;
        EditorGUI.PropertyField(new Rect(rect.x, rect.y, rect.width - 38, SplinePlusEditor.ElementHeight), follower.FindPropertyRelative("Speed"), new GUIContent("Speed"));

        rect.y = rect.y + SplinePlusEditor.ElementHeight + SplinePlusEditor.ElementHeightSpace;
        EditorGUI.IntField(new Rect(rect.x, rect.y, rect.width - 38, SplinePlusEditor.ElementHeight), new GUIContent("Branch key"), follower.FindPropertyRelative("_BranchKey").intValue);


        if (GUI.Button(new Rect(rect.width, rect.y, 20, SplinePlusEditor.ElementHeight), new GUIContent(SplinePlusEditor.Return.image, "Add branch index"), GUIStyle.none))
        {
            follower.FindPropertyRelative("_BranchKey").intValue = SPData.Selections._BranchKey;
            follower.serializedObject.ApplyModifiedProperties();

            SPData.SplinePlus.FollowerClass.Follow(SPData);
        }



        var transButtonString = follower.FindPropertyRelative("Trans").boolValue ? "Local" : "World";

        rect.y = rect.y + SplinePlusEditor.ElementHeight + SplinePlusEditor.ElementHeightSpace;
        var position = EditorGUI.Vector3Field(new Rect(rect.x, rect.y, rect.width - 40, SplinePlusEditor.ElementHeight), "Position", follower.FindPropertyRelative("Position").vector3Value);

        if (follower.FindPropertyRelative("Position").vector3Value != position)
        {
            follower.FindPropertyRelative("Position").vector3Value = position;
            follower.serializedObject.ApplyModifiedProperties();

            SPData.SplinePlus.FollowerClass.Follow(SPData);
        }

        if (GUI.Button(new Rect(rect.width, rect.y, 40, 15), new GUIContent(transButtonString)))
        {
            follower.FindPropertyRelative("Trans").boolValue = !follower.FindPropertyRelative("Trans").boolValue;
            follower.serializedObject.ApplyModifiedProperties();

            SPData.SplinePlus.FollowerClass.Follow(SPData);
        }


        GUI.enabled = follower.FindPropertyRelative("Rot").boolValue ? true : false;
        rect.y      = rect.y + SplinePlusEditor.ElementHeight + SplinePlusEditor.ElementHeightSpace;
        var rotation = EditorGUI.Vector3Field(new Rect(rect.x, rect.y, rect.width - 40, SplinePlusEditor.ElementHeight), "Rotation", follower.FindPropertyRelative("Rotation").vector3Value);

        if (follower.FindPropertyRelative("Rotation").vector3Value != rotation)
        {
            follower.FindPropertyRelative("Rotation").vector3Value = rotation;
            follower.serializedObject.ApplyModifiedProperties();

            SPData.SplinePlus.FollowerClass.Follow(SPData);
        }
        GUI.enabled = true;

        GUIStyle RotButtonStyle = new GUIStyle(GUI.skin.button);

        RotButtonStyle.normal = follower.FindPropertyRelative("Rot").boolValue ? RotButtonStyle.onNormal : RotButtonStyle.normal;
        if (GUI.Button(new Rect(rect.width, rect.y, 40, 15), new GUIContent("Rot"), RotButtonStyle))
        {
            follower.FindPropertyRelative("Rot").boolValue = !follower.FindPropertyRelative("Rot").boolValue;
            follower.serializedObject.ApplyModifiedProperties();

            SPData.SplinePlus.FollowerClass.Follow(SPData);
        }
    }
Esempio n. 3
0
    public void Train(SPData SPData, SplinePlusEditor SPEditor)
    {
        SerializedObject   serializedObject = new SerializedObject(SPData.SplinePlus);
        SerializedProperty trainsSP         = serializedObject.FindProperty("SPData").FindPropertyRelative("Trains");

        SPEditor.TrainsList = new ReorderableList(serializedObject, trainsSP, true, false, true, true);
        SPEditor.TrainsList.drawHeaderCallback = (Rect rect) =>
        {
            EditorGUI.LabelField(new Rect(rect.x, rect.y, rect.width, SplinePlusEditor.ElementHeight), "Trains", EditorStyles.boldLabel);
        };

        SPEditor.TrainsList.drawElementCallback = (Rect rect, int index, bool isActive, bool isFocused) =>
        {
            SerializedProperty train    = trainsSP.GetArrayElementAtIndex(index);
            SerializedProperty WagonsSP = train.FindPropertyRelative("Wagons");

            //wagons ReorderableList setup
            // add new wagons ReorderableList to the WagonsList whenever new train is added
            if (SPEditor.WagonsList.Count <= index)
            {
                SPEditor.WagonsList.Add(new ReorderableList(train.serializedObject, WagonsSP, true, false, true, true));
                WagonsDraw(SPData, SPEditor, train, index);
            }

            var trainExpandContent = (train.FindPropertyRelative("Show").boolValue) ? SplinePlusEditor.Plus : SplinePlusEditor.Minus;
            if (GUI.Button(new Rect(rect.x, rect.y, 20, SplinePlusEditor.ElementHeight), trainExpandContent, GUIStyle.none))
            {
                train.FindPropertyRelative("Show").boolValue = !train.FindPropertyRelative("Show").boolValue;
                trainsSP.serializedObject.ApplyModifiedProperties();
            }

            train.FindPropertyRelative("Name").stringValue = EditorGUI.TextField(new Rect(rect.x + 40, rect.y, rect.width - 120, SplinePlusEditor.ElementHeight), train.FindPropertyRelative("Name").stringValue, EditorStyles.boldLabel);
            if (GUI.Button(new Rect(rect.x + 20, rect.y, 20, SplinePlusEditor.ElementHeight), new GUIContent(SplinePlusEditor.Settings.image, "Follower settings"), GUIStyle.none))
            {
                FollowerSettingsWind wind = (FollowerSettingsWind)EditorWindow.GetWindow(typeof(FollowerSettingsWind), true, "Follower settings", true);
                wind.Show();
                wind.ShowWindow(SPData, train, FollowerSettingsType.Train);
            }
            var trainIsActiveContent = (train.FindPropertyRelative("IsActive").boolValue) ? SplinePlusEditor.On : SplinePlusEditor.Off;
            if (GUI.Button(new Rect(rect.width, rect.y, 40, SplinePlusEditor.ElementHeight), new GUIContent(trainIsActiveContent.image, "Enable/disable train animation"), GUIStyle.none))
            {
                train.FindPropertyRelative("IsActive").boolValue = !train.FindPropertyRelative("IsActive").boolValue;
                trainsSP.serializedObject.ApplyModifiedProperties();
            }
            if (train.FindPropertyRelative("Show").boolValue)
            {
                rect.y = rect.y + SplinePlusEditor.ElementHeight + SplinePlusEditor.ElementHeightSpace;
                EditorGUI.BeginChangeCheck();
                var progress = EditorGUI.FloatField(new Rect(rect.x, rect.y, rect.width - 38, SplinePlusEditor.ElementHeight), "Progress", train.FindPropertyRelative("Progress").floatValue);
                if (EditorGUI.EndChangeCheck())
                {
                    if (progress > SPData.DictBranches[train.FindPropertyRelative("_BranchKey").intValue].BranchDistance)
                    {
                        train.FindPropertyRelative("Progress").floatValue = SPData.DictBranches[train.FindPropertyRelative("_BranchKey").intValue].BranchDistance;
                        trainsSP.serializedObject.ApplyModifiedProperties();

                        return;
                    }

                    train.FindPropertyRelative("Progress").floatValue = progress;

                    UpdateAllWagons(SPData, train);
                }

                rect.y = rect.y + SplinePlusEditor.ElementHeight + SplinePlusEditor.ElementHeightSpace;
                EditorGUI.BeginChangeCheck();
                var speed = EditorGUI.FloatField(new Rect(rect.x, rect.y, rect.width - 38, SplinePlusEditor.ElementHeight), "Speed", train.FindPropertyRelative("Speed").floatValue);
                if (EditorGUI.EndChangeCheck())
                {
                    train.FindPropertyRelative("Speed").floatValue = speed;
                    trainsSP.serializedObject.ApplyModifiedProperties();
                }
                rect.y = rect.y + SplinePlusEditor.ElementHeight + SplinePlusEditor.ElementHeightSpace;
                EditorGUI.IntField(new Rect(rect.x, rect.y, rect.width - 38, SplinePlusEditor.ElementHeight), "Branch key", train.FindPropertyRelative("_BranchKey").intValue);


                if (GUI.Button(new Rect(rect.width, rect.y, 20, SplinePlusEditor.ElementHeight), new GUIContent(SplinePlusEditor.Return.image, "Add branch index"), GUIStyle.none))
                {
                    serializedObject.Update();
                    train.FindPropertyRelative("_BranchKey").intValue = SPData.Selections._BranchKey;
                    UpdateAllWagons(SPData, train);
                }

                rect.y = rect.y + SplinePlusEditor.ElementHeight + SplinePlusEditor.ElementHeightSpace;
                SPEditor.WagonsList[index].DoList(new Rect(rect.x, rect.y, rect.width, rect.height));
            }
        };


        SPEditor.TrainsList.elementHeightCallback = (int index) =>
        {
            SerializedProperty train = trainsSP.GetArrayElementAtIndex(index);
            if (!train.FindPropertyRelative("Show").boolValue)
            {
                return(SplinePlusEditor.ElementHeight + 2);
            }

            var d = 7;
            if (train.FindPropertyRelative("Wagons").arraySize == 0)
            {
                return((SplinePlusEditor.ElementHeight + SplinePlusEditor.ElementHeightSpace) * (d + 1));
            }
            for (int i = 0; i < train.FindPropertyRelative("Wagons").arraySize; i++)
            {
                d += (train.FindPropertyRelative("Wagons").GetArrayElementAtIndex(i).FindPropertyRelative("Show").boolValue) ? 5 : 1;
            }
            var height = (SplinePlusEditor.ElementHeight + SplinePlusEditor.ElementHeightSpace) * d;
            return(height);
        };

        SPEditor.TrainsList.onAddCallback = (ReorderableList list) =>
        {
            var t = trainsSP.arraySize;
            trainsSP.InsertArrayElementAtIndex(t);

            trainsSP.GetArrayElementAtIndex(t).FindPropertyRelative("AnimationEvents").boolValue         = true;
            trainsSP.GetArrayElementAtIndex(t).FindPropertyRelative("IsForward").boolValue               = true;
            trainsSP.GetArrayElementAtIndex(t).FindPropertyRelative("Name").stringValue                  = "Train name";
            trainsSP.GetArrayElementAtIndex(t).FindPropertyRelative("Wagons").arraySize                  = 0;
            trainsSP.GetArrayElementAtIndex(t).FindPropertyRelative("Show").boolValue                    = true;
            trainsSP.GetArrayElementAtIndex(t).FindPropertyRelative("IsActive").boolValue                = true;
            trainsSP.GetArrayElementAtIndex(t).FindPropertyRelative("_BranchKey").intValue               = 0;
            trainsSP.GetArrayElementAtIndex(t).FindPropertyRelative("Progress").floatValue               = 0;
            trainsSP.GetArrayElementAtIndex(t).FindPropertyRelative("Speed").floatValue                  = 2.5f;
            trainsSP.GetArrayElementAtIndex(t).FindPropertyRelative("Acceleration").floatValue           = 0;
            trainsSP.GetArrayElementAtIndex(t).FindPropertyRelative("BrakesForce").floatValue            = 2;
            trainsSP.GetArrayElementAtIndex(t).FindPropertyRelative("_FollowerAnimation").enumValueIndex = 0;
            trainsSP.GetArrayElementAtIndex(t).FindPropertyRelative("Position").vector3Value             = Vector3.zero;
            trainsSP.GetArrayElementAtIndex(t).FindPropertyRelative("Rotation").vector3Value             = Vector3.zero;

            trainsSP.serializedObject.ApplyModifiedProperties();
        };

        SPEditor.TrainsList.onRemoveCallback = (ReorderableList list) =>
        {
            trainsSP.DeleteArrayElementAtIndex(SPEditor.TrainsList.index);
            if (FollowerSettingsWind.oldWindw != null)
            {
                FollowerSettingsWind.oldWindw.Close();
            }
            trainsSP.serializedObject.ApplyModifiedProperties();
            return;
        };
    }