public static RuntimeMonoBehaviour Create(string name, Func <bool> updateDelegate)
        {
            Initialize();

            GameObject gameObject = new GameObject("RuntimeMonoBehaviour - " + name, typeof(MonoBehaviourHook));

            gameObject.transform.parent = globalGameObject.transform;

            RuntimeMonoBehaviour runtimeMonoBehaviour = new RuntimeMonoBehaviour(gameObject, name, updateDelegate);

            gameObject.GetComponent <MonoBehaviourHook>().OnUpdated = runtimeMonoBehaviour.Update;

            runtimeMonoBehaviourDictionary.Add(name, runtimeMonoBehaviour);

            return(runtimeMonoBehaviour);
        }
Esempio n. 2
0
        public static void DoCameraShake(float intensity, float duration)
        {
            Vector3 originalCameraPosition = Camera.main.transform.position;
            Vector3 lastCameraPosition     = Vector3.zero;

            RuntimeMonoBehaviour.Create
            (
                "Camera Shake",
                () =>
            {
                duration -= Time.unscaledDeltaTime;
                Vector3 randomPosition         = new Vector3(UnityEngine.Random.Range(-1f, 1f), UnityEngine.Random.Range(-1f, 1f)).normalized *intensity;
                Camera.main.transform.position = Camera.main.transform.position - lastCameraPosition + randomPosition;
                lastCameraPosition             = randomPosition;

                if (duration <= 0f)
                {
                    Camera.main.transform.position = originalCameraPosition;
                }

                return(duration <= 0f);
            }
            );
        }