Exemplo n.º 1
0
        public static void Shake(GameObject gameObject, float intensity, float duration, float interval, float delay = 0, bool shakeOnlyVisible = true, GameObject sourceObject = null)
        {
            // 震动父节点而不是相机本身,因为相机同时要跟随人移动,会造成坐标混乱,画面闪屏
            if (gameObject.transform.parent == null || gameObject.transform.parent.name != PARENT_NAME)
            {
                var shakerParent = new GameObject(PARENT_NAME);
                shakerParent.transform.parent        = gameObject.transform.parent;
                shakerParent.transform.localPosition = gameObject.transform.localPosition;
                shakerParent.transform.localScale    = gameObject.transform.localScale;
                shakerParent.transform.localRotation = gameObject.transform.localRotation;

                ObjectUtility.AttachToParentAndResetLocalTrans(shakerParent, gameObject);
            }

            var shakerParentObj = gameObject.transform.parent.gameObject;

            var cameraShaker = shakerParentObj.GetComponent <CameraShaker>();

            if (cameraShaker == null)
            {
                cameraShaker             = shakerParentObj.AddComponent <CameraShaker>();
                cameraShaker.AutoDestroy = true;
            }

            if (shakeOnlyVisible && sourceObject != null)
            {
                Vector2 viewPortPoint = gameObject.GetComponent <Camera>().WorldToViewportPoint(sourceObject.transform.position);
                if (viewPortPoint.x < 0 || viewPortPoint.x > 1 || viewPortPoint.y < 0 || viewPortPoint.y > 1)
                {
                    return;
                }
            }

            cameraShaker.Shake(intensity, duration, interval, delay, shakeOnlyVisible);
        }
Exemplo n.º 2
0
    public FXController Spawm()
    {
        if (released)
        {
            return(null);
        }

        if (template == null)
        {
            return(null);
        }

        FXController fx = null;

        if (despawmFXs.Count == 0 || despawmFXs[despawmFXs.Count - 1].GetNextPoolTime() > Time.time)
        {
#if FX_POOL_METRICS
            allocCount++;
#endif

            // Instantiate new FX
            var go = GameObject.Instantiate(template.gameObject) as GameObject;

            // Template is inactive, set new go active
            go.SetActive(true);

            // Get FXController
            fx = go.GetComponent <FXController>();

            // Add a root GO as default
            fx.CreateRoot();
            Object.DontDestroyOnLoad(fx.Root);

            // Set pool
            fx.FXPool = this;
        }
        else
        {
#if FX_POOL_METRICS
            spawmFromPoolCount++;
#endif

            // Get from pool
            fx = despawmFXs[despawmFXs.Count - 1];
            despawmFXs.RemoveAt(despawmFXs.Count - 1);

            // Attach scene root
            ObjectUtility.AttachToParentAndResetLocalTrans(null, fx.Root);

            // Pooled Fx is inactive, set active
            fx.Root.gameObject.SetActive(true);
        }

        // Start FX
        fx.Start();

        return(fx);
    }
Exemplo n.º 3
0
    private AudioData CreateAudioData()
    {
        var audioData = new AudioData();

        audioData.audioSource             = new GameObject("AudioSource").AddComponent <AudioSource>();
        audioData.audioSource.playOnAwake = false;
        ObjectUtility.AttachToParentAndResetLocalTrans(this.gameObject, audioData.audioSource.gameObject);

        DontDestroyOnLoad(audioData.audioSource.gameObject);

        return(audioData);
    }
Exemplo n.º 4
0
    public void Despawm(FXController fx)
    {
        if (released)
        {
            Object.Destroy(fx.Root.gameObject);
        }
        else
        {
#if FX_POOL_METRICS
            despawmToPoolCount++;
#endif

            // Reset data
            fx.ClearFinishCallback();
            fx.SetFreeToLastPoolTime(Time.time);

            Debug.Assert(fx.Root.parent != root);

            // Return to pool
            ObjectUtility.AttachToParentAndResetLocalTrans(root, fx.Root);
            fx.Root.gameObject.SetActive(false);
            despawmFXs.Insert(0, fx);
        }
    }