コード例 #1
0
ファイル: GenericPresetsUtil.cs プロジェクト: chadiik/PCG-MCT
    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++;
        }
    }
コード例 #2
0
ファイル: GenericPresetsUtil.cs プロジェクト: chadiik/PCG-MCT
    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);
        }
    }