Ejemplo n.º 1
0
    ///////////////////////////////////////////////////////////
    // constructor. creates a default state using the values
    // currently set on the component, then loads the presets
    // referenced in the passed list of states.
    ///////////////////////////////////////////////////////////
    public vp_StateManager(vp_Component component, List <vp_StateInfo> states)
    {
        m_States    = states;
        m_Component = component;

        // create default state and add it to the list
        m_Component.RefreshDefaultState();

        // refresh the initial state, needed for being able to save
        // partial presets in the editor
#if UNITY_EDITOR
        m_Component.RefreshInitialState();
#endif

        // load up the preset of each user assigned state
        foreach (vp_StateInfo s in m_States)
        {
            if (s.Preset == null)
            {
                s.Preset = new vp_ComponentPreset();
            }
            if (s.TextAsset != null)
            {
                s.Preset.LoadFromTextAsset(s.TextAsset);
            }
        }
    }
    private int m_TargetId  = 0;        // id of the last modified state (for triggering enable / disable callbacks)


    /// <summary>
    /// manages a list of states and corresponding presets for a
    /// component. loads the presets into memory on startup, and
    /// allows applying them from memory to the component.
    /// states are enabled in a layered manner, that is: the
    /// default state is always alive, and any enabled states are
    /// applied on top of it in the order of which they were enabled.
    ///
    /// this class doesn't store any preset data between sessions.
    /// it is merely used to manipulate the component using a list
    /// of states that is sent along at startup. it is very silent
    /// and forgiving; it won't complain if a state isn't found
    /// (since providing a certain state should not be considered
    /// mandatory for a component, and states can be set recursively).
    /// it will also ignore empty presets
    /// </summary>
    public vp_StateManager(vp_Component component, List <vp_State> states)
    {
        m_States    = states;
        m_Component = component;

        // create default state and add it to the list
        m_Component.RefreshDefaultState();

        // refresh the initial state, needed for being able to save
        // partial presets in the editor
#if UNITY_EDITOR
        m_Component.RefreshInitialState();
#endif

        // load states and initialize the state id dictionary
        m_StateIds = new Dictionary <string, int>(System.StringComparer.CurrentCulture);
        foreach (vp_State s in m_States)
        {
            s.StateManager = this;

            // store the name and list index of each state in a dictionary for
            // fast lookup. IMPORTANT: the state list (m_States) must never be
            // modified at runtime (i.e. have states reordered, added, renamed
            // or removed) or the dictionary (m_StateIds) will be out of date
            if (!m_StateIds.ContainsKey(s.Name))
            {
                m_StateIds.Add(s.Name, m_States.IndexOf(s));
            }
            else
            {
                Debug.LogWarning("Warning: " + m_Component.GetType() + " on '" + m_Component.name + "' has more than one state named: '" + s.Name + "'. Only the topmost one will be used.");
                m_States[m_DefaultId].StatesToBlock.Add(m_States.IndexOf(s));
            }

            // load up the preset of each user assigned state and
            if (s.Preset == null)
            {
                s.Preset = new vp_ComponentPreset();
            }
            if (s.TextAsset != null)
            {
                s.Preset.LoadFromTextAsset(s.TextAsset);
            }
        }

        // the default state of a component is always the last one in the list
        m_DefaultId = m_States.Count - 1;
    }
Ejemplo n.º 3
0
	private int m_TargetId = 0;		// id of the last modified state (for triggering enable / disable callbacks)


	/// <summary>
	/// manages a list of states and corresponding presets for a
	/// component. loads the presets into memory on startup, and
	/// allows applying them from memory to the component.
	/// states are enabled in a layered manner, that is: the
	/// default state is always alive, and any enabled states are
	/// applied on top of it in the order of which they were enabled.
	/// 
	/// this class doesn't store any preset data between sessions.
	/// it is merely used to manipulate the component using a list
	/// of states that is sent along at startup. it is very silent
	/// and forgiving; it won't complain if a state isn't found
	/// (since providing a certain state should not be considered
	/// mandatory for a component, and states can be set recursively).
	/// it will also ignore empty presets
	/// </summary>
	public vp_StateManager(vp_Component component, List<vp_State> states)
	{

		m_States = states;
		m_Component = component;

		// create default state and add it to the list
		m_Component.RefreshDefaultState();

		// refresh the initial state, needed for being able to save
		// partial presets in the editor
#if UNITY_EDITOR
			m_Component.RefreshInitialState();
#endif

		// load states and initialize the state id dictionary
		m_StateIds = new Dictionary<string, int>(System.StringComparer.CurrentCulture);
		foreach (vp_State s in m_States)
		{

			s.StateManager = this;

			// store the name and list index of each state in a dictionary for
			// fast lookup. IMPORTANT: the state list (m_States) must never be
			// modified at runtime (i.e. have states reordered, added, renamed
			// or removed) or the dictionary (m_StateIds) will be out of date
			if (!m_StateIds.ContainsKey(s.Name))
				m_StateIds.Add(s.Name, m_States.IndexOf(s));
			else
			{
				Debug.LogWarning("Warning: " + m_Component.GetType() + " on '" + m_Component.name + "' has more than one state named: '" + s.Name + "'. Only the topmost one will be used.");
				m_States[m_DefaultId].StatesToBlock.Add(m_States.IndexOf(s));
			}

			// load up the preset of each user assigned state and
			if (s.Preset == null)
				s.Preset = new vp_ComponentPreset();
			if (s.TextAsset != null)
				s.Preset.LoadFromTextAsset(s.TextAsset);

		}

		// the default state of a component is always the last one in the list
		m_DefaultId = m_States.Count - 1;

	}
Ejemplo n.º 4
0
    ///////////////////////////////////////////////////////////
    // combines all the states in the list to a temporary state,
    // and sets it on the component
    ///////////////////////////////////////////////////////////
    private void CombineStates()
    {
        // go backwards so default state is applied first
        for (int v = m_States.Count - 1; v > -1; v--)
        {
            if (m_States[v].Enabled)
            {
                if (m_States[v].Preset != null)
                {
                    vp_ComponentPreset.Apply(m_Component, m_States[v].Preset);
                }
            }
        }

#if UNITY_EDITOR
        m_Component.RefreshInitialState();
#endif
    }
Ejemplo n.º 5
0
    /// <summary>
    /// combines all the states in the list to a temporary state,
    /// and sets it on the component
    /// </summary>
    public void CombineStates()
    {
        //Debug.Log("combineStates for " + this.m_Component.transform + " -> " + this.m_Component.GetType());

        // go backwards so default state is applied first
        for (int v = m_States.Count - 1; v > -1; v--)
        {
            if (v != m_DefaultId)
            {
                if (!m_States[v].Enabled)
                {
                    continue;
                }

                if (m_States[v].Blocked)
                {
                    continue;
                }

                if (m_States[v].TextAsset == null)
                {
                    continue;
                }
            }

            if (m_States[v].Preset == null)
            {
                continue;
            }

            if (m_States[v].Preset.ComponentType == null)
            {
                continue;
            }

            vp_ComponentPreset.Apply(m_Component, m_States[v].Preset);
        }


#if UNITY_EDITOR
        m_Component.RefreshInitialState();
#endif
    }
Ejemplo n.º 6
0
    private List<vp_StateInfo> m_States = null; // list sent from the component at startup

    #endregion Fields

    #region Constructors

    ///////////////////////////////////////////////////////////
    // constructor. creates a default state using the values
    // currently set on the component, then loads the presets
    // referenced in the passed list of states.
    ///////////////////////////////////////////////////////////
    public vp_StateManager(vp_Component component, List<vp_StateInfo> states)
    {
        m_States = states;
        m_Component = component;

        // create default state and add it to the list
        m_Component.RefreshDefaultState();

        // refresh the initial state, needed for being able to save
        // partial presets in the editor
        #if UNITY_EDITOR
        m_Component.RefreshInitialState();
        #endif

        // load up the preset of each user assigned state
        foreach (vp_StateInfo s in m_States)
        {
            if(s.Preset == null)
                s.Preset = new vp_ComponentPreset();
            if (s.TextAsset != null)
                s.Preset.LoadFromTextAsset(s.TextAsset);
        }
    }