Exemplo n.º 1
0
        public void AddTrigger(SplineTrigger.Type t, UnityAction <Transform> call, Transform value)
        {
            SplineTrigger trigger = ScriptableObject.CreateInstance <SplineTrigger>();

            trigger.Create(t, call, value);
            AddTrigger(trigger);
        }
Exemplo n.º 2
0
        public void AddTrigger(SplineTrigger.Type t, UnityAction call)
        {
            SplineTrigger trigger = ScriptableObject.CreateInstance <SplineTrigger>();

            trigger.Create(t, call);
            AddTrigger(trigger);
        }
Exemplo n.º 3
0
        public void AddTrigger(SplineTrigger.Type t, UnityAction <Transform> call, Transform value, double position = 0.0, SplineTrigger.Type type = SplineTrigger.Type.Double)
        {
            SplineTrigger trigger = ScriptableObject.CreateInstance <SplineTrigger>();

            trigger.Create(t, call, value);
            trigger.position = position;
            trigger.type     = type;
            AddTrigger(trigger);
        }
Exemplo n.º 4
0
        public static void TriggerArray(ref SplineTrigger[] triggers, ref int open)
        {
            EditorGUILayout.BeginVertical();
            for (int i = 0; i < triggers.Length; i++)
            {
                if (triggers[i] == null)
                {
                    GUILayout.Box("", GUILayout.Width(Screen.width - 30), GUILayout.Height(20));
                    Rect rect = GUILayoutUtility.GetLastRect();
                    GUI.BeginGroup(rect);
                    GUI.Label(new Rect(25, 2, rect.width - 90, 16), "NULL");
                    if (GUI.Button(new Rect(rect.width - 62, 2, 45, 16), "x"))
                    {
                        SplineTrigger[] newTriggers = new SplineTrigger[triggers.Length - 1];
                        for (int n = 0; n < triggers.Length; n++)
                        {
                            if (n < i)
                            {
                                newTriggers[n] = triggers[n];
                            }
                            else if (n == i)
                            {
                                continue;
                            }
                            else
                            {
                                newTriggers[n - 1] = triggers[n];
                            }
                        }
                        triggers = newTriggers;
                    }
                    GUI.EndGroup();
                    continue;
                }
                Color col = new Color(triggers[i].color.r, triggers[i].color.g, triggers[i].color.b);
                if (open == i)
                {
                    col.a = 1f;
                }
                else
                {
                    col.a = 0.6f;
                }
                GUI.color = col;
                GUILayout.Box("", GUILayout.Width(Screen.width - 30), GUILayout.Height(20));
                GUI.color = Color.white;
                Rect boxRect = GUILayoutUtility.GetLastRect();
                GUI.BeginGroup(boxRect);
                Rect nameRect = new Rect(25, 2, boxRect.width - 90, 16);
                if (open == i)
                {
                    triggers[i].name = GUI.TextField(nameRect, triggers[i].name);
                }
                else
                {
                    GUI.Label(nameRect, triggers[i].name);
                    if (nameRect.Contains(Event.current.mousePosition) && Event.current.type == EventType.MouseDown)
                    {
                        open = i;
                        GUI.EndGroup();
                        break;
                    }
                }
                triggers[i].enabled = GUI.Toggle(new Rect(2, 2, 21, 16), triggers[i].enabled, "");
                triggers[i].color   = EditorGUI.ColorField(new Rect(boxRect.width - 62, 2, 45, 16), triggers[i].color);
                GUI.EndGroup();
                if (i != open)
                {
                    continue;
                }
                EditorGUILayout.BeginHorizontal();
                EditorGUILayout.BeginVertical();
                triggers[i].position = EditorGUILayout.Slider("Position", (float)triggers[i].position, 0f, 1f);
                triggers[i].type     = (SplineTrigger.Type)EditorGUILayout.EnumPopup("Type", triggers[i].type);
                GUILayout.Label("Actions");
                for (int n = 0; n < triggers[i].actions.Length; n++)
                {
                    EditorGUILayout.BeginHorizontal();
                    if (GUILayout.Button("x", GUILayout.Width(20)))
                    {
                        SplineAction[] newActions = new SplineAction[triggers[i].actions.Length - 1];
                        for (int x = 0; x < triggers[i].actions.Length; x++)
                        {
                            if (x < n)
                            {
                                newActions[x] = triggers[i].actions[x];
                            }
                            else if (x == n)
                            {
                                continue;
                            }
                            else
                            {
                                newActions[x - 1] = triggers[i].actions[x];
                            }
                        }
                        triggers[i].actions = newActions;
                        break;
                    }
                    ActionField(triggers[i].actions[n]);
                    EditorGUILayout.EndHorizontal();
                }

                if (GUILayout.Button("New Action"))
                {
                    SplineAction[] newActions = new SplineAction[triggers[i].actions.Length + 1];
                    triggers[i].actions.CopyTo(newActions, 0);
                    newActions[newActions.Length - 1] = new SplineAction();
                    triggers[i].actions = newActions;
                }


                EditorGUILayout.EndVertical();
                EditorGUILayout.BeginVertical();
                if (GUILayout.Button("-", GUILayout.Width(20)))
                {
                    open = -1;
                    EditorGUILayout.EndVertical();
                    EditorGUILayout.EndHorizontal();
                    break;
                }
                if (GUILayout.Button("x", GUILayout.Width(20)))
                {
                    SplineTrigger[] newTriggers = new SplineTrigger[triggers.Length - 1];
                    for (int n = 0; n < triggers.Length; n++)
                    {
                        if (n < i)
                        {
                            newTriggers[n] = triggers[n];
                        }
                        else if (n == i)
                        {
                            continue;
                        }
                        else
                        {
                            newTriggers[n - 1] = triggers[n];
                        }
                    }
                    triggers = newTriggers;
                }
                if (GUILayout.Button("d", GUILayout.Width(20)))
                {
                    SplineTrigger newTrigger = ScriptableObject.CreateInstance <SplineTrigger>();
                    newTrigger      = (SplineTrigger)GameObject.Instantiate(triggers[i]);
                    newTrigger.name = "Trigger " + (triggers.Length + 1);
                    SplineTrigger[] newTriggers = new SplineTrigger[triggers.Length + 1];
                    triggers.CopyTo(newTriggers, 0);
                    newTriggers[newTriggers.Length - 1] = newTrigger;
                    triggers = newTriggers;
                    open     = triggers.Length - 1;
                }
                if (i > 0)
                {
                    if (GUILayout.Button("▲", GUILayout.Width(20)))
                    {
                        SplineTrigger temp = triggers[i - 1];
                        triggers[i - 1] = triggers[i];
                        triggers[i]     = temp;
                    }
                }
                if (i < triggers.Length - 1)
                {
                    if (GUILayout.Button("▼", GUILayout.Width(20)))
                    {
                        SplineTrigger temp = triggers[i + 1];
                        triggers[i + 1] = triggers[i];
                        triggers[i]     = temp;
                    }
                }
                EditorGUILayout.EndVertical();
                EditorGUILayout.EndHorizontal();
                EditorGUILayout.Space();
            }
            EditorGUILayout.EndVertical();
            EditorGUILayout.BeginHorizontal();
            if (GUILayout.Button("Add new"))
            {
                SplineTrigger newTrigger = ScriptableObject.CreateInstance <SplineTrigger>();
                newTrigger.Create(addTriggerType);
                newTrigger.name = "Trigger " + (triggers.Length + 1);
                SplineTrigger[] newTriggers = new SplineTrigger[triggers.Length + 1];
                triggers.CopyTo(newTriggers, 0);
                newTriggers[newTriggers.Length - 1] = newTrigger;
                triggers = newTriggers;
            }
            addTriggerType = (SplineTrigger.Type)EditorGUILayout.EnumPopup(addTriggerType);
            EditorGUILayout.EndHorizontal();
        }