Пример #1
0
    // Create and return PrefabAnim object
    // animName - name of the prefab
    // prefabPath - asset path for the prefab
    // pos - target position for initialized prefab
    // startDelay - delay after which the prefab should be activated
    // animDuration - duration of prefabAnim, callback for anim complete will be send after this duration along with destroying the object
    public static PrefabAnim PrefabAnim(string animName, string prefabPath, Vector3 pos, float startDelay, float animDuration = 5.0f)
    {
        StringBuilder prefabName = new StringBuilder(prefabPath);

        prefabName.Append(animName);
        GameObject vfxPrefab = Object.Instantiate(Resources.Load(prefabName.ToString()), pos, Quaternion.identity) as GameObject;

        vfxPrefab.SetActive(false);
        PrefabAnim newAnim = new PrefabAnim();

        newAnim.targetObj    = vfxPrefab;
        newAnim.startDelay   = startDelay;
        newAnim.animDuration = animDuration;

        return(newAnim);
    }
Пример #2
0
    // Updates PrefabAnim anim type
    // Returns true if anim is over
    private static bool UpdatePrefabAnim(PrefabAnim prefabAnim)
    {
        bool bAnimComplete = false;

        if (!prefabAnim.targetObj.activeSelf)
        {
            prefabAnim.targetObj.SetActive(true);
//			if(prefabAnim.animDuration > 0)
//				GameObject.Destroy(prefabAnim.targetObj, prefabAnim.animDuration);
        }
        else
        {
            bAnimComplete = (Time.time - prefabAnim.initTime) > prefabAnim.animDuration;
            if (bAnimComplete)
            {
                GameObject.Destroy(prefabAnim.targetObj);
            }
        }

        return(bAnimComplete);
    }