Exemple #1
0
 private void AddAction()
 {
     SplineAction[] newActions = new SplineAction[actions.Length + 1];
     actions.CopyTo(newActions, 0);
     newActions[newActions.Length - 1] = new SplineAction();
     actions = newActions;
 }
Exemple #2
0
 private void AddAction()
 {
     SplineAction[] array = new SplineAction[actions.Length + 1];
     actions.CopyTo(array, 0);
     array[array.Length - 1] = new SplineAction();
     actions = array;
 }
Exemple #3
0
        public static void TriggerArray(ref Trigger[] triggers, ref int open)
        {
            EditorGUI.BeginChangeCheck();
            EditorGUILayout.BeginVertical();
            for (int i = 0; i < triggers.Length; i++)
            {
                if (triggers[i] == null)
                {
                    GUILayout.Box("", GUILayout.Width(EditorGUIUtility.currentViewWidth - 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"))
                    {
                        Trigger[] newTriggers = new Trigger[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(EditorGUIUtility.currentViewWidth - 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     = (Trigger.Type)EditorGUILayout.EnumPopup("Type", triggers[i].type);
                triggers[i].workOnce = EditorGUILayout.Toggle("Work Once", triggers[i].workOnce);
                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)))
                {
                    Trigger[] newTriggers = new Trigger[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>();
                    Trigger newTrigger = new Trigger();
                    //newTrigger = (SplineTrigger)GameObject.Instantiate(triggers[i]);
                    newTrigger.color    = triggers[i].color;
                    newTrigger.enabled  = triggers[i].enabled;
                    newTrigger.position = triggers[i].position;
                    newTrigger.type     = triggers[i].type;
                    newTrigger.name     = "Trigger " + (triggers.Length + 1);
                    Trigger[] newTriggers = new Trigger[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)))
                    {
                        Trigger temp = triggers[i - 1];
                        triggers[i - 1] = triggers[i];
                        triggers[i]     = temp;
                    }
                }
                if (i < triggers.Length - 1)
                {
                    if (GUILayout.Button("▼", GUILayout.Width(20)))
                    {
                        Trigger 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>();
                Trigger newTrigger = new Trigger();
                newTrigger.Create(addTriggerType);
                newTrigger.name = "Trigger " + (triggers.Length + 1);
                Trigger[] newTriggers = new Trigger[triggers.Length + 1];
                triggers.CopyTo(newTriggers, 0);
                newTriggers[newTriggers.Length - 1] = newTrigger;
                triggers = newTriggers;
            }
            addTriggerType = (Trigger.Type)EditorGUILayout.EnumPopup(addTriggerType);
            EditorGUILayout.EndHorizontal();
            if (EditorGUI.EndChangeCheck())
            {
                SceneView.RepaintAll();
            }
        }
Exemple #4
0
        public static void ActionField(SplineAction action)
        {
            EditorGUILayout.BeginHorizontal();
            action.target = (Object)EditorGUILayout.ObjectField(action.target, typeof(Object), true, GUILayout.MinWidth(120));
            if (action.target == null)
            {
                EditorGUILayout.EndHorizontal();
                return;
            }
            GameObject gameObject = null;
            Transform  transform  = null;
            Component  component  = null;

            try
            {
                gameObject = (GameObject)action.target;
                transform  = gameObject.transform;
            }
            catch
            {
                try
                {
                    transform  = (Transform)action.target;
                    gameObject = transform.gameObject;
                }
                catch
                {
                    try
                    {
                        component  = (Component)action.target;
                        transform  = component.transform;
                        gameObject = component.gameObject;
                    }
                    catch (System.InvalidCastException ex3)
                    {
                        Debug.LogError(ex3.Message);
                        Debug.LogError("Supplied object is not a GameObject and is not a component");
                    }
                }
            }

            List <MethodInfo> methods = new List <MethodInfo>();
            List <string>     names   = new List <string>();
            int           selected    = 0;
            MethodInfo    method      = action.GetMethod();
            List <Object> targets     = new List <Object>();

            if (gameObject != null)
            {
                List <MethodInfo> addRange = GetVoidMethods(gameObject);
                for (int i = 0; i < addRange.Count; i++)
                {
                    names.Add("GameObject/" + addRange[i].Name);
                    targets.Add(gameObject);
                    if (method == addRange[i])
                    {
                        selected = names.Count - 1;
                    }
                }
                methods.AddRange(addRange);
                Component[] components = gameObject.GetComponents <Component>();
                for (int i = 0; i < components.Length; i++)
                {
                    string typeName = components[i].GetType().ToString();
                    addRange = GetVoidMethods(components[i]);
                    methods.AddRange(addRange);
                    for (int n = 0; n < addRange.Count; n++)
                    {
                        names.Add(typeName + "/" + addRange[n].Name);
                        targets.Add(components[i]);
                        if (method == addRange[n])
                        {
                            selected = names.Count - 1;
                        }
                    }
                }
            }

            selected = EditorGUILayout.Popup(selected, names.ToArray(), GUILayout.MinWidth(120));
            if (selected >= 0)
            {
                action.target = targets[selected];
                action.SetMethod(methods[selected]);
            }
            if (method != null)
            {
                ParameterInfo[] parameters = method.GetParameters();
                if (parameters.Length > 0)
                {
                    System.Type paramType = parameters[0].ParameterType;

                    if (paramType == typeof(int))
                    {
                        action.intValue = EditorGUILayout.IntField(action.intValue, GUILayout.MaxWidth(120));
                    }
                    else if (paramType == typeof(float))
                    {
                        action.floatValue = EditorGUILayout.FloatField(action.floatValue);
                    }
                    else if (paramType == typeof(double))
                    {
                        action.doubleValue = EditorGUILayout.FloatField((float)action.doubleValue);
                    }
                    else if (paramType == typeof(bool))
                    {
                        action.boolValue = EditorGUILayout.Toggle(action.boolValue);
                    }
                    else if (paramType == typeof(string))
                    {
                        action.stringValue = EditorGUILayout.TextField(action.stringValue);
                    }
                    else if (paramType == typeof(GameObject))
                    {
                        action.goValue = (GameObject)EditorGUILayout.ObjectField(action.goValue, typeof(GameObject), true);
                    }
                    else if (paramType == typeof(Transform))
                    {
                        action.transformValue = (Transform)EditorGUILayout.ObjectField(action.transformValue, typeof(Transform), true);
                    }
                }
            }
            EditorGUILayout.EndHorizontal();
        }
Exemple #5
0
 public void AddAction(SplineAction action)
 {
     AddAction();
     actions[actions.Length - 1] = action;
 }
Exemple #6
0
 public LengthEvent(Type t, SplineAction a)
 {
     type   = t;
     action = a;
 }