Beispiel #1
0
    public static IEnumerator TransitionFromToCoroutine(object originData, GenericPreset goal, MonoBehaviour target, float duration, UnityAction onCompleted = null, GenericPreset store = null)
    {
        GenericPreset origin = null;

        if (originData == null && target is MaterialExplorer)
        {
            origin = GenericPreset.Create((( MaterialExplorer )target).Explore(goal));
        }

        if (originData is string [])
        {
            GenericPreset.Create(target, originData as string []);
        }

        if (store == null)
        {
            store = ScriptableObject.CreateInstance <GenericPreset> ();
        }


        float startTime = Time.time;
        float t         = 0f;

        while (t < 1f)
        {
            //Debug.LogFormat ( "Transition generic preset {0}", t );

            GenericPreset.Lerp(origin, goal, t, store);
            t = (Time.time - startTime) / duration;

            if (target is MaterialExplorer)
            {
                store.ApplyMaterial((( MaterialExplorer )target).material);
            }
            else
            {
                store.Apply(target);
            }

            yield return(new WaitForFixedUpdate());
        }

        if (target is MaterialExplorer)
        {
            store.ApplyMaterial((( MaterialExplorer )target).material);
        }
        else
        {
            store.Apply(target);
        }
    }
Beispiel #2
0
    private void LerpPresets()
    {
        if (m_LerpPresetStore == null)
        {
            m_LerpPresetStore = ScriptableObject.CreateInstance <GenericPreset> ();
        }

        int numPresets = lerpPresets.Length;

        if (m_LerpPresetIndex >= numPresets)
        {
            m_LerpPresetIndex = 0;
        }

        int nextIndex = m_LerpPresetIndex + 1 < numPresets ? m_LerpPresetIndex + 1: 0;

        if (lerpPresets [m_LerpPresetIndex] != null && lerpPresets [nextIndex] != null)
        {
            GenericPreset.Lerp(lerpPresets [m_LerpPresetIndex], lerpPresets [nextIndex], Mathf.Sin(Time.time * .2f) * .5f + .5f, m_LerpPresetStore);

            if (target is MaterialExplorer)
            {
                m_LerpPresetStore.ApplyMaterial((( MaterialExplorer )target).material);
            }
            else
            {
                m_LerpPresetStore.Apply(target);
            }

            m_LerpPresetIndex++;
        }
    }
Beispiel #3
0
    protected void Update()
    {
        if (savePreset)
        {
            savePreset = false;
            CreatePreset();
        }

        if (preset != null)
        {
            if (target is MaterialExplorer)
            {
                MaterialExplorer matTarget = ( MaterialExplorer )target;
                if (matTarget.properties == null || matTarget.properties.Count != preset.properties.Count)
                {
                    matTarget.FromPreset(preset);
                }
                preset.ApplyMaterial(matTarget.material);
            }
            else
            {
                preset.Apply(target);
            }

            preset = null;
        }

        int numPresets = lerpPresets.Length;

        if (numPresets > 1)
        {
            LerpPresets();
        }
    }
Beispiel #4
0
    protected void Update()
    {
        if (update)
        {
            update = false;
            Explore(null);
        }

        if (preset != null)
        {
            if (properties == null)
            {
                FromPreset(preset);
            }

            preset.ApplyMaterial(material);

            preset = null;
        }
    }