// Start is called before the first frame update
    void Start()
    {
        masterRail = this.gameObject.GetComponentInParent <PlayerMovementRailV1>();

        if (stopPoint && !masterRail.loop)
        {
            if (stopCollider == null)
            {
                GenerateStopCollider();
            }
        }

        if (enableRailJoin)
        {
            if (switchRailCollider == null)
            {
                GenerateSwitchCollider();
            }
        }
        else
        {
            if (switchRailCollider != null)
            {
                DestroyImmediate(switchRailCollider);
            }
        }
    }
Пример #2
0
 // Start is called before the first frame update
 void Start()
 {
     charScript = FindObjectOfType <TombiCharacterController>();
     //ikHandler = charScript.GetComponent<IKHandler>();
     coll = this.GetComponent <SphereCollider>();
     if (charScript != null)
     {
         rigidBody = charScript.GetComponent <Rigidbody>();
     }
     camScript               = FindObjectOfType <Typo.Utilities.Cameras.BasicCameraController>();
     currentActiveRail       = FindObjectOfType <PlayerMovementRailV1>();
     oldSwingForceMultiplier = swingForceMultiplier;
 }
    public override void OnInspectorGUI()
    {
        base.OnInspectorGUI();


        PlayerMovementRailV1 t = (PlayerMovementRailV1)target;

        test = t;

        if (GUILayout.Button("Add Point"))
        {
            t.AddPoint();
        }

        if (GUILayout.Button("Remove Point"))
        {
            t.RemovePoint();
        }
        GUILayout.Space(20f);
    }
    private static void ShowButtons(SerializedProperty list, GUIStyle toggled, GUIStyle untoggled, int index)
    {
        PlayerMovementRailV1 rail = (PlayerMovementRailV1)list.GetArrayElementAtIndex(index).objectReferenceValue;

        if (list.GetArrayElementAtIndex(index).objectReferenceValue != null)
        {
            if (GUILayout.Button((rail.editorSelected ? "Exit" : "Edit"), (rail.editorSelected ? toggled : untoggled), miniButtonWidth))
            {
                if (!rail.editorSelected && EditorUtility.DisplayDialog("Edit START",
                                                                        "Do you want to edit rail '" + rail.name + "'?" + Environment.NewLine + Environment.NewLine +
                                                                        "This will cancel every ongoing editing operations for other rails." + Environment.NewLine + Environment.NewLine + "The operation can't be reversed.",
                                                                        "Yes", "No"))
                {
                    for (int i = 0; i < list.arraySize; i++)
                    {
                        PlayerMovementRailV1 temprail = (PlayerMovementRailV1)list.GetArrayElementAtIndex(i).objectReferenceValue;
                        temprail.editorSelected = false;
                    }
                    rail.editorSelected = true;
                    rail.railGizmoColor = Color.red;

                    rail.isEditing         = true;
                    targetScript.isEditing = true;
                }
                else if (rail.editorSelected && EditorUtility.DisplayDialog("Edit END", "Do you want to save and exit edit mode?", "Yes", "No"))
                {
                    rail.editorSelected = false;
                    rail.railGizmoColor = Color.green;

                    rail.isEditing         = false;
                    targetScript.isEditing = false;
                }
            }
            GUIStyle s = new GUIStyle(GUI.skin.button);
            s.normal.textColor = Color.red;

            if (!rail.isEditing)
            {
                if (GUILayout.Button("Delete", s, miniButtonWidth))
                {
                    if (EditorUtility.DisplayDialog("Rail Remove", "Do you want to remove rail '" + rail.name + "'?" + Environment.NewLine + "The operation can't be reversed.", "Yes", "No"))
                    {
                        targetScript.RemoveRail(rail);
                    }
                }
            }
            else
            {
                if (GUILayout.Button("Add Connection", new GUILayoutOption[4] {
                    GUILayout.MaxWidth(100), GUILayout.MaxHeight(30), GUILayout.MinWidth(100), GUILayout.MinHeight(30)
                }))
                {
                    //if (EditorUtility.DisplayDialog("Add Connection", "Do you want to add a new connection?", "Yes", "No"))
                    {
                        rail.AddConnection();
                    }
                }
            }

            if (UnityEngine.Event.current.type == EventType.KeyDown)
            {
                if (UnityEngine.Event.current.keyCode == KeyCode.Escape)
                {
                    rail.editorSelected = false;
                }
            }
        }
    }
    static void DrawFields(SerializedProperty rail)
    {
        PlayerMovementRailV1 r = (PlayerMovementRailV1)rail.objectReferenceValue;

        EditorGUILayout.Vector3Field("Switch collider size:", r.railSwitchColliderSize);

        if (r.connections != null && r.connections.Count > 0)
        {
            EditorGUI.indentLevel++;

            r.editorConnectionsCollapsed = EditorGUILayout.Foldout(r.editorConnectionsCollapsed, "Rail Connections", true);

            if (r.editorConnectionsCollapsed)
            {
                int i = 0;

                HorizontalLine(Color.grey);

                foreach (PlayerMovementRailConnection conn in r.connections.ToArray())
                {
                    if (conn != null)
                    {
                        GUIStyle s = new GUIStyle(EditorStyles.boldLabel);
                        GUIStyle b = new GUIStyle(EditorStyles.miniButton);
                        b.normal.textColor = Color.red;

                        EditorGUILayout.BeginHorizontal();

                        EditorGUILayout.LabelField(conn.name, s);
                        if (targetScript.isEditing)
                        {
                            if (GUILayout.Button("Remove", b, new GUILayoutOption[4] {
                                GUILayout.MaxWidth(50), GUILayout.MaxHeight(20), GUILayout.MinWidth(50), GUILayout.MinHeight(20)
                            }))
                            {
                                r.RemoveConnection(i);
                            }
                        }

                        EditorGUILayout.EndHorizontal();
                        conn.name = EditorGUILayout.TextField("Name:", conn.name);

                        string[] railPointOptions = new string[0];
                        int      i2 = 0;

                        foreach (PlayerMovementRailV1 rail1 in targetScript.rails)
                        {
                            if (rail1.points != null && rail1.points.Length > 0)
                            {
                                foreach (GameObject point in rail1.points)
                                {
                                    System.Array.Resize(ref railPointOptions, railPointOptions.Length + 1);
                                    railPointOptions[i2] = "[" + i2 + "] " + rail1.name + "_" + point.name;
                                    i2++;
                                }
                            }
                        }
                        conn.point1Options = railPointOptions;
                        conn.point2Options = railPointOptions;

                        conn.point1SelectedOptionIndex = EditorGUILayout.Popup("Point 1", conn.point1SelectedOptionIndex, conn.point1Options);
                        conn.point2SelectedOptionIndex = EditorGUILayout.Popup("Point 2", conn.point2SelectedOptionIndex, conn.point2Options);

                        conn.direction = (PlayerMovementRailConnection.eConnectionDirection)EditorGUILayout.EnumPopup("Direction", conn.direction);

                        HorizontalLine(Color.grey);
                    }
                    i++;
                }
            }
            EditorGUI.indentLevel--;
        }
        else
        {
            EditorGUILayout.HelpBox("No connections available for this rail." + Environment.NewLine + "To add new connections enter edit mode and click on 'Add Connections' button.", MessageType.Warning);
        }
    }
    private static void ShowElements(SerializedProperty list, GUIStyle toggled, GUIStyle untoggled, EditorListOption options)
    {
        bool
            showElementLabels = (options & EditorListOption.ElementLabels) != 0,
            showButtons       = (options & EditorListOption.Buttons) != 0;

        for (int i = 0; i < list.arraySize; i++)
        {
            if (list.GetArrayElementAtIndex(i).objectReferenceValue != null)
            {
                PlayerMovementRailV1 rail = (PlayerMovementRailV1)list.GetArrayElementAtIndex(i).objectReferenceValue;

                if (targetScript.isEditing == true)
                {
                    if (rail.isEditing)
                    {
                        HorizontalLine(Color.red);
                        GUIStyle s = new GUIStyle(EditorStyles.boldLabel);
                        EditorGUILayout.LabelField("Rail Name: " + rail.name + "", s);

                        if (showButtons)
                        {
                            EditorGUILayout.BeginHorizontal();
                        }
                        if (showElementLabels)
                        {
                            EditorGUILayout.ObjectField("Rail Object", list.GetArrayElementAtIndex(i).objectReferenceValue, typeof(GameObject), true);
                            EditorGUILayout.EndHorizontal();
                            EditorGUILayout.BeginHorizontal();
                        }
                        else
                        {
                            EditorGUILayout.ObjectField("Rail Object", list.GetArrayElementAtIndex(i).objectReferenceValue, typeof(GameObject), true);
                            EditorGUILayout.EndHorizontal();
                        }

                        EditorGUI.BeginDisabledGroup(false);
                        rail.railSwitchColliderSize = EditorGUILayout.Vector3Field("Switch collider size:", rail.railSwitchColliderSize);
                        DrawFields(list.GetArrayElementAtIndex(i));
                        EditorGUI.EndDisabledGroup();
                        EditorGUILayout.BeginHorizontal();
                        if (showButtons)
                        {
                            ShowButtons(list, toggled, untoggled, i);
                            EditorGUILayout.EndHorizontal();
                            GUILayout.Space(10f);
                        }
                        HorizontalLine(Color.red);
                    }
                }
                else
                {
                    HorizontalLine(Color.grey);
                    GUIStyle s = new GUIStyle(EditorStyles.boldLabel);
                    EditorGUILayout.LabelField("Rail Name: " + rail.name + "", s);
                    rail.editorCollapsed = EditorGUILayout.Foldout(rail.editorCollapsed, "Parameters", true);


                    if (rail.editorCollapsed)
                    {
                        EditorGUI.BeginDisabledGroup(true);
                        if (showButtons)
                        {
                            EditorGUILayout.BeginHorizontal();
                        }
                        if (showElementLabels)
                        {
                            EditorGUILayout.ObjectField("Rail Object", list.GetArrayElementAtIndex(i).objectReferenceValue, typeof(GameObject), true);
                            EditorGUILayout.EndHorizontal();
                            EditorGUILayout.BeginHorizontal();
                        }
                        else
                        {
                            EditorGUILayout.ObjectField("Rail Object", list.GetArrayElementAtIndex(i).objectReferenceValue, typeof(GameObject), true);
                            EditorGUILayout.EndHorizontal();
                        }
                        DrawFields(list.GetArrayElementAtIndex(i));

                        EditorGUI.EndDisabledGroup();
                    }

                    EditorGUILayout.BeginHorizontal();
                    if (showButtons)
                    {
                        ShowButtons(list, toggled, untoggled, i);
                        EditorGUILayout.EndHorizontal();
                        GUILayout.Space(10f);
                    }
                }
            }
        }
        //if (showButtons && list.arraySize == 0 && GUILayout.Button(addButtonContent, EditorStyles.miniButton))
        //{
        //    list.arraySize += 1;
        //}
    }
Пример #7
0
 public void EditRail(PlayerMovementRailV1 railToEdit)
 {
     railToEdit.editorSelected = true;
 }
Пример #8
0
 public void RemoveRail(PlayerMovementRailV1 rail)
 {
     this.rails.Remove(rail);
     DestroyImmediate(rail.gameObject);
 }