///////////////////////////////////////////////////////////
    // copies component values into the default state's preset.
    // if needed, creates & adds default state to the state list.
    // to be called on app startup and statemanager recombine
    ///////////////////////////////////////////////////////////
#if UNITY_EDITOR
    public void RefreshInitialState()
    {
        m_InitialState        = null;
        m_InitialState        = new vp_StateInfo(GetType().Name, "Internal_Initial", null);
        m_InitialState.Preset = new vp_ComponentPreset();
        m_InitialState.Preset.InitFromComponent(this);
    }
Exemple #2
0
    ///////////////////////////////////////////////////////////
    // draws a button showing if a state is on or off, allowing
    // the user to toggle states at runtime. will also show
    // a text saying if the state is currently disallowed
    ///////////////////////////////////////////////////////////
    public static void RunTimeStateField(vp_Component component, vp_StateInfo state, List <vp_StateInfo> stateList)
    {
        EditorGUILayout.BeginHorizontal();

        GUI.color = m_ColorTransparentWhite;
        if (!state.Enabled)
        {
            GUILayout.Space(20);
            GUI.enabled = true;
            GUILayout.Label((stateList.Count - stateList.IndexOf(state) - 1).ToString() + ":", vp_EditorGUIUtility.RightAlignedPathStyle, GUILayout.MinWidth(20), GUILayout.MaxWidth(20));
            GUILayout.BeginHorizontal();
            if (GUILayout.Button(state.Name, vp_EditorGUIUtility.CenteredBoxStyle, GUILayout.MinWidth(90), GUILayout.MaxWidth(90)))
            {
                vp_Component[] compos = component.gameObject.GetComponentsInChildren <vp_Component>();
                foreach (vp_Component c in compos)
                {
                    c.StateManager.SetState(state.Name, true);
                    c.Refresh();
                }
            }
            if (!state.Allowed)
            {
                GUILayout.Label("(Disallowed)");
            }
            GUILayout.EndHorizontal();
            GUI.color = m_ColorTransparentWhite;
        }
        else
        {
            GUILayout.Space(20);
            GUILayout.Label((stateList.Count - stateList.IndexOf(state) - 1).ToString() + ":", vp_EditorGUIUtility.RightAlignedPathStyle, GUILayout.MinWidth(20), GUILayout.MaxWidth(20));
            if (GUILayout.Button(state.Name, vp_EditorGUIUtility.CenteredBoxStyleBold, GUILayout.MinWidth(90), GUILayout.MaxWidth(90)))
            {
                vp_Component[] compos = component.gameObject.GetComponentsInChildren <vp_Component>();
                foreach (vp_Component c in compos)
                {
                    c.StateManager.SetState(state.Name, false);
                    c.Refresh();
                }
            }
        }

        if (state.Name != "Default" && state.TextAsset == null)
        {
            GUILayout.TextField("<- Warning: No preset!", vp_EditorGUIUtility.NoteStyle, GUILayout.MinWidth(100));
        }

        EditorGUILayout.EndHorizontal();
    }
    ///////////////////////////////////////////////////////////
    // sees if the component has a default state. if so, makes
    // sure it's in index zero of the list, if not, creates it.
    ///////////////////////////////////////////////////////////
    public void RefreshDefaultState()
    {
        vp_StateInfo defaultState = null;

        if (States.Count == 0)
        {
            // there are no states, so create default state
            defaultState = new vp_StateInfo(GetType().Name, "Default", null);
            States.Add(defaultState);
        }
        else
        {
            for (int v = States.Count - 1; v > -1; v--)
            {
                if (States[v].Name == "Default")
                {
                    // found default state, make sure it's in the back
                    defaultState = States[v];
                    States.Remove(defaultState);
                    States.Add(defaultState);
                }
            }
            if (defaultState == null)
            {
                // there are states, but no default state so create it
                defaultState = new vp_StateInfo(GetType().Name, "Default", null);
                States.Add(defaultState);
            }
        }

        if (defaultState.Preset == null || defaultState.Preset.ComponentType == null)
        {
            defaultState.Preset = new vp_ComponentPreset();
        }

        if (defaultState.TextAsset == null)
        {
            defaultState.Preset.InitFromComponent(this);
        }

        defaultState.Enabled = true;            // default state is always enabled

        m_DefaultState = defaultState;
    }
Exemple #4
0
    ///////////////////////////////////////////////////////////
    // draws a slot to which the user can drag a preset TextAsset
    ///////////////////////////////////////////////////////////
    private static void PresetField(vp_StateInfo state)
    {
        TextAsset orig = state.TextAsset;

        state.TextAsset = (TextAsset)EditorGUILayout.ObjectField(state.TextAsset, typeof(TextAsset), false);
        if (state.TextAsset != orig)
        {
            if (state.TextAsset != null)
            {
                if ((vp_ComponentPreset.GetFileTypeFromAsset(state.TextAsset) == null ||
                     vp_ComponentPreset.GetFileTypeFromAsset(state.TextAsset).Name != state.TypeName))
                {
                    vp_MessageBox.Create(vp_MessageBox.Mode.OK, "Error", "Error: The file '" + state.TextAsset.name + " ' does not contain a preset of type '" + state.TypeName + "'.");
                    state.TextAsset = orig;
                    return;
                }
            }
        }
    }
    ///////////////////////////////////////////////////////////
    // draws a disabled preset field for the built-in default
    // state, making the user aware of the state
    ///////////////////////////////////////////////////////////
    public static void DefaultStateField(vp_StateInfo state)
    {
        EditorGUILayout.BeginHorizontal();

        GUI.enabled = false;
        GUILayout.Label("Default", "Textfield", GUILayout.MinWidth(90), GUILayout.MaxWidth(90));

        PresetField(state);

        GUILayout.TextField("(editor)", vp_EditorGUIUtility.NoteStyle, GUILayout.MinWidth(100));

        EditorGUILayout.Space();
        GUI.color = Color.clear;
        GUILayout.Button("...", GUILayout.MinWidth(24), GUILayout.MaxWidth(24));
        GUILayout.Button("X", GUILayout.MinWidth(24), GUILayout.MaxWidth(24));
        GUI.color = Color.white;
        GUI.enabled = true;

        EditorGUILayout.EndHorizontal();
    }
Exemple #6
0
    ///////////////////////////////////////////////////////////
    // draws a disabled preset field for the built-in default
    // state, making the user aware of the state
    ///////////////////////////////////////////////////////////
    public static void DefaultStateField(vp_StateInfo state)
    {
        EditorGUILayout.BeginHorizontal();

        GUI.enabled = false;
        GUILayout.Label("Default", "Textfield", GUILayout.MinWidth(90), GUILayout.MaxWidth(90));

        PresetField(state);

        GUILayout.TextField("(editor)", vp_EditorGUIUtility.NoteStyle, GUILayout.MinWidth(100));

        EditorGUILayout.Space();
        GUI.color = Color.clear;
        GUILayout.Button("...", GUILayout.MinWidth(24), GUILayout.MaxWidth(24));
        GUILayout.Button("X", GUILayout.MinWidth(24), GUILayout.MaxWidth(24));
        GUI.color   = Color.white;
        GUI.enabled = true;

        EditorGUILayout.EndHorizontal();
    }
 ///////////////////////////////////////////////////////////
 // draws a slot to which the user can drag a preset TextAsset
 ///////////////////////////////////////////////////////////
 private static void PresetField(vp_StateInfo state)
 {
     TextAsset orig = state.TextAsset;
     state.TextAsset = (TextAsset)EditorGUILayout.ObjectField(state.TextAsset, typeof(TextAsset), false);
     if (state.TextAsset != orig)
     {
         if (state.TextAsset != null)
         {
             if((vp_ComponentPreset.GetFileTypeFromAsset(state.TextAsset) == null ||
             vp_ComponentPreset.GetFileTypeFromAsset(state.TextAsset).Name != state.TypeName))
             {
                 vp_MessageBox.Create(vp_MessageBox.Mode.OK, "Error", "Error: The file '" + state.TextAsset.name + " ' does not contain a preset of type '" + state.TypeName + "'.");
                 state.TextAsset = orig;
                 return;
             }
         }
     }
 }
    ///////////////////////////////////////////////////////////
    // draws a row displaying a preset state name, a path and
    // buttons for browsing the path + deleting the state
    ///////////////////////////////////////////////////////////
    public static void StateField(vp_StateInfo state, List <vp_StateInfo> stateList)
    {
        GUI.enabled = !Application.isPlaying;	// only allow preset field interaction in 'stopped' mode

        EditorGUILayout.BeginHorizontal();

        string orig = state.Name;
        if (state.Name == "Default")
        {
            GUI.enabled = false;
            EditorGUILayout.TextField(state.Name, GUILayout.MinWidth(90), GUILayout.MaxWidth(90));
            GUI.enabled = true;
        }
        else
        {
            state.Name = EditorGUILayout.TextField(state.Name, GUILayout.MinWidth(90), GUILayout.MaxWidth(90));
        }

        if ((orig != state.Name) && (state.Name == "Default"))
        {
            vp_MessageBox.Create(vp_MessageBox.Mode.OK, "Error", "'Default' is a reserved state name.");
            state.Name = orig;
        }

        PresetField(state);

        if (state.Name == "Default")
        {
            if (state.TextAsset == null)
            {
                GUI.enabled = false;
                GUILayout.TextField("(Inspector)", vp_EditorGUIUtility.NoteStyle, GUILayout.MinWidth(60));
            }
            else
            {
                GUI.enabled = true;
                if (GUILayout.Button("Unlock", vp_EditorGUIUtility.SmallButtonStyle, GUILayout.MinWidth(30), GUILayout.MinHeight(15)))
                {
                    state.TextAsset = null;
                }
            }
        }
        else
        {
            if (stateList.IndexOf(state) == 0)
                GUI.enabled = false;

            GUI.SetNextControlName ("state");
            if (GUILayout.Button("^", vp_EditorGUIUtility.SmallButtonStyle, GUILayout.MinWidth(15), GUILayout.MaxWidth(15), GUILayout.MinHeight(15)))
            {
                int i = stateList.IndexOf(state);
                if (i != 0)
                {
                    stateList.Remove(state);
                    stateList.Insert(i - 1, state);
                }
                // focus this button to get rid of possible textfield focus,
                // or the textfields won't update properly when moving state
                GUI.FocusControl("state");
            }

            GUI.enabled = true;

            if (GUILayout.Button("X", vp_EditorGUIUtility.SmallButtonStyle, GUILayout.MinWidth(15), GUILayout.MaxWidth(15), GUILayout.MinHeight(15)))
                stateList.Remove(state);

        }

        GUI.enabled = true;

        EditorGUILayout.EndHorizontal();
    }
    ///////////////////////////////////////////////////////////
    // draws a button showing if a state is on or off, allowing
    // the user to toggle states at runtime. will also show
    // a text saying if the state is currently disallowed
    ///////////////////////////////////////////////////////////
    public static void RunTimeStateField(vp_Component component, vp_StateInfo state, List<vp_StateInfo> stateList)
    {
        EditorGUILayout.BeginHorizontal();

        GUI.color = m_ColorTransparentWhite;
        if (!state.Enabled)
        {
            GUILayout.Space(20);
            GUI.enabled = true;
            GUILayout.Label((stateList.Count - stateList.IndexOf(state) - 1).ToString() + ":", vp_EditorGUIUtility.RightAlignedPathStyle, GUILayout.MinWidth(20), GUILayout.MaxWidth(20));
            GUILayout.BeginHorizontal();
            if(GUILayout.Button(state.Name, vp_EditorGUIUtility.CenteredBoxStyle, GUILayout.MinWidth(90), GUILayout.MaxWidth(90)))
            {
                vp_Component[] compos = component.gameObject.GetComponentsInChildren<vp_Component>();
                foreach (vp_Component c in compos)
                {
                    c.StateManager.SetState(state.Name, true);
                    c.Refresh();
                }
            }
            if (!state.Allowed)
                GUILayout.Label("(Disallowed)");
            GUILayout.EndHorizontal();
            GUI.color = m_ColorTransparentWhite;
        }
        else
        {
            GUILayout.Space(20);
            GUILayout.Label((stateList.Count - stateList.IndexOf(state) - 1).ToString() + ":", vp_EditorGUIUtility.RightAlignedPathStyle, GUILayout.MinWidth(20), GUILayout.MaxWidth(20));
            if (GUILayout.Button(state.Name, vp_EditorGUIUtility.CenteredBoxStyleBold, GUILayout.MinWidth(90), GUILayout.MaxWidth(90)))
            {
                vp_Component[] compos = component.gameObject.GetComponentsInChildren<vp_Component>();
                foreach (vp_Component c in compos)
                {
                    c.StateManager.SetState(state.Name, false);
                    c.Refresh();
                }
            }
        }

        if (state.Name != "Default" && state.TextAsset == null)
            GUILayout.TextField("<- Warning: No preset!", vp_EditorGUIUtility.NoteStyle, GUILayout.MinWidth(100));

        EditorGUILayout.EndHorizontal();
    }
 ///////////////////////////////////////////////////////////
 // copies component values into the default state's preset.
 // if needed, creates & adds default state to the state list.
 // to be called on app startup and statemanager recombine
 ///////////////////////////////////////////////////////////
 public void RefreshInitialState()
 {
     m_InitialState = null;
     m_InitialState = new vp_StateInfo(GetType().Name, "Internal_Initial", null);
     m_InitialState.Preset = new vp_ComponentPreset();
     m_InitialState.Preset.InitFromComponent(this);
 }
    ///////////////////////////////////////////////////////////
    // sees if the component has a default state. if so, makes
    // sure it's in index zero of the list, if not, creates it.
    ///////////////////////////////////////////////////////////
    public void RefreshDefaultState()
    {
        vp_StateInfo defaultState = null;

        if (States.Count == 0)
        {
            // there are no states, so create default state
            defaultState = new vp_StateInfo(GetType().Name, "Default", null);
            States.Add(defaultState);
        }
        else
        {
            for (int v = States.Count - 1; v > -1; v--)
            {
                if (States[v].Name == "Default")
                {
                    // found default state, make sure it's in the back
                    defaultState = States[v];
                    States.Remove(defaultState);
                    States.Add(defaultState);
                }
            }
            if (defaultState == null)
            {
                // there are states, but no default state so create it
                defaultState = new vp_StateInfo(GetType().Name, "Default", null);
                States.Add(defaultState);
            }
        }

        if (defaultState.Preset == null || defaultState.Preset.ComponentType == null)
            defaultState.Preset = new vp_ComponentPreset();

        if(defaultState.TextAsset == null)
            defaultState.Preset.InitFromComponent(this);

        defaultState.Enabled = true;	// default state is always enabled

        m_DefaultState = defaultState;
    }
 ///////////////////////////////////////////////////////////
 // moves a state to the top of the list (index 0)
 ///////////////////////////////////////////////////////////
 public void BringToFront(vp_StateInfo state)
 {
     m_States.Remove(state);
     m_States.Insert(0, state);
 }
 ///////////////////////////////////////////////////////////
 // moves a state to the top of the list (index 0)
 ///////////////////////////////////////////////////////////
 public void BringToFront(vp_StateInfo state)
 {
     m_States.Remove(state);
     m_States.Insert(0, state);
 }
Exemple #14
0
    ///////////////////////////////////////////////////////////
    // draws a row displaying a preset state name, a path and
    // buttons for browsing the path + deleting the state
    ///////////////////////////////////////////////////////////
    public static void StateField(vp_StateInfo state, List <vp_StateInfo> stateList)
    {
        GUI.enabled = !Application.isPlaying;           // only allow preset field interaction in 'stopped' mode

        EditorGUILayout.BeginHorizontal();

        string orig = state.Name;

        if (state.Name == "Default")
        {
            GUI.enabled = false;
            EditorGUILayout.TextField(state.Name, GUILayout.MinWidth(90), GUILayout.MaxWidth(90));
            GUI.enabled = true;
        }
        else
        {
            state.Name = EditorGUILayout.TextField(state.Name, GUILayout.MinWidth(90), GUILayout.MaxWidth(90));
        }

        if ((orig != state.Name) && (state.Name == "Default"))
        {
            vp_MessageBox.Create(vp_MessageBox.Mode.OK, "Error", "'Default' is a reserved state name.");
            state.Name = orig;
        }

        PresetField(state);

        if (state.Name == "Default")
        {
            if (state.TextAsset == null)
            {
                GUI.enabled = false;
                GUILayout.TextField("(Inspector)", vp_EditorGUIUtility.NoteStyle, GUILayout.MinWidth(60));
            }
            else
            {
                GUI.enabled = true;
                if (GUILayout.Button("Unlock", vp_EditorGUIUtility.SmallButtonStyle, GUILayout.MinWidth(30), GUILayout.MinHeight(15)))
                {
                    state.TextAsset = null;
                }
            }
        }
        else
        {
            if (stateList.IndexOf(state) == 0)
            {
                GUI.enabled = false;
            }

            GUI.SetNextControlName("state");
            if (GUILayout.Button("^", vp_EditorGUIUtility.SmallButtonStyle, GUILayout.MinWidth(15), GUILayout.MaxWidth(15), GUILayout.MinHeight(15)))
            {
                int i = stateList.IndexOf(state);
                if (i != 0)
                {
                    stateList.Remove(state);
                    stateList.Insert(i - 1, state);
                }
                // focus this button to get rid of possible textfield focus,
                // or the textfields won't update properly when moving state
                GUI.FocusControl("state");
            }

            GUI.enabled = true;

            if (GUILayout.Button("X", vp_EditorGUIUtility.SmallButtonStyle, GUILayout.MinWidth(15), GUILayout.MaxWidth(15), GUILayout.MinHeight(15)))
            {
                stateList.Remove(state);
            }
        }

        GUI.enabled = true;

        EditorGUILayout.EndHorizontal();
    }