Ejemplo n.º 1
0
        internal static void Repeat(OperationTreeDescription treeDescription, int?repeatCount = null)
        {
            var isCounted = repeatCount.HasValue;
            var count     = 0;

            var controlOp = new Operation(endAction: () =>
            {
                if (isCounted)
                {
                    count++;
                }
                if (isCounted && count >= repeatCount)
                {
                    return;
                }

                var isCancelled = treeDescription.IsCancelled();
                if (isCancelled)
                {
                    ManagedLog.Log($"Not restarting {nameof(OperationTreeDescription)}, root: {treeDescription.Root.Name}", ManagedLog.Type.Verbose);
                }
                else
                {
                    ManagedLog.Log($"Restarting {nameof(OperationTreeDescription)}, root: {treeDescription.Root.Name}", ManagedLog.Type.Verbose);
                    treeDescription.Start();
                }
            });

            treeDescription.AddOperation(controlOp);

            if (!treeDescription.IsWaitingOrRunning())
            {
                treeDescription.Start();
            }
        }
Ejemplo n.º 2
0
        private void OnValidate()
        {
            var col = GetComponent <Collider>();

            if (!col)
            {
                ManagedLog.LogError($"{Internal_GameObject.name} doesn't have any Collider component!", gameObject);
            }
            if (col && !col.isTrigger
                #region Editor
                && UnityEditor.EditorUtility.DisplayDialog("TriggerEvent", "TriggerEvent collider is not set as trigger, set it now?", "OK", "Cancel")
                #endregion
                )
            {
                col.isTrigger = true;
            }

            if (!_PhysicsObject)
            {
                _PhysicsObject = GetComponent <PhysicsObject>();
            }
            if (!_PhysicsObject)
            {
                _PhysicsObject = Internal_GameObject.AddComponent <PhysicsObject>();
            }
        }
Ejemplo n.º 3
0
        public UniformScale(
            Transform transform,
            float duration,
            float targetScale,
            float delay    = 0f,
            EaseCurve?ease = null,
            string name    = null,
            OperationSkipCondition skipCondition = null)
        {
            _targetScale   = targetScale;
            _transform     = transform;
            _duration      = duration;
            Delay          = delay;
            _skipCondition = skipCondition;

            _ease = ease;

            _updateAction = UpdateAction;

            Name = name ?? $"{(_transform ? _transform.name + " "  : "")} {nameof(UniformScale)}";

            BindTo(transform);

#if UNITY_EDITOR    // Check if initial scale is uniform.
            if (Math.Abs(_transform.localScale.x - _transform.localScale.y) > Mathf.Epsilon ||
                Math.Abs(_transform.localScale.x - _transform.localScale.z) > Mathf.Epsilon)
            {
                ManagedLog.LogError($"{transform.name} is scale is not uniform.");
            }
#endif
        }
Ejemplo n.º 4
0
        public void SetIsVisible(bool isVisible)
        {
            Internal_GameObject.SetActive(isVisible);

#if UNITY_EDITOR
            if (!Internal_GameObject.activeInHierarchy)
            {
                var firstDisabledParent = FindDisabledParent(Internal_Transform);
                ManagedLog.LogError($"{gameObject.GetScenePath()} will not be visible because one of it's parents ({firstDisabledParent.gameObject.GetScenePath()} is disabled. ");
            }
            Transform FindDisabledParent(Transform t)
            {
                while (true)
                {
                    if (!t.parent.gameObject.activeSelf)
                    {
                        return(t.parent);
                    }
                    if (t.parent == null)
                    {
                        return(null);
                    }
                    t = t.parent;
                }
            }
#endif
        }
Ejemplo n.º 5
0
        private static void AddAllComponentsInScene <T>(Scene arg0) where T : Component
        {
            var addedCount        = 0;
            var allObjectsInScene = arg0.GetRootGameObjects();

            foreach (var gameObject in allObjectsInScene)
            {
                var components = gameObject.GetComponentsInChildren <T>();
                addedCount += components.Length;
                switch (components)
                {
                case View[] views:
                    Views.AddRange(views);
                    foreach (var view in views)
                    {
                        view.Internal_OnLoad();
                    }
                    break;

                case ControllerBase[] controllers:
                    Controllers.AddRange(controllers);
                    break;
                }
            }

            if (addedCount > 0)
            {
                ManagedLog.Log($"Added {addedCount} {typeof(T).Name} from {arg0.name} scene.", ManagedLog.Type.Structure);
            }
        }
Ejemplo n.º 6
0
 private static void LogEvent(object msg)
 {
     if (!_logEvents)
     {
         return;
     }
     ManagedLog.Log(msg, ManagedLog.Type.Structure);
 }
Ejemplo n.º 7
0
 private static void LogUpdate(object msg)
 {
     if (!_logDrawUpdates)
     {
         return;
     }
     ManagedLog.Log(msg);
 }
Ejemplo n.º 8
0
 private static void OnEditorApplicationOnPlayModeStateChanged(PlayModeStateChange change)
 {
     if (change != PlayModeStateChange.ExitingPlayMode)
     {
         return;
     }
     ManagedLog.LogMethod(type: ManagedLog.Type.Structure);
     StateMachines.Clear();
 }
Ejemplo n.º 9
0
        private static void InitializeOnLoadMethod()
        {
            ManagedLog.LogMethod(type: ManagedLog.Type.Structure);

            PlayerLoopUtilities.AppendToPlayerLoop <Update.ScriptRunBehaviourUpdate>(typeof(BasicStateMachineEngine), Update);
#if UNITY_EDITOR
            EditorApplication.playModeStateChanged += OnEditorApplicationOnPlayModeStateChanged;
#endif
        }
Ejemplo n.º 10
0
 public static void Stop(Coroutine coroutine)
 {
     if (coroutine == null)
     {
         ManagedLog.LogError($"Tried to stop a null coroutine.");
         return;
     }
     Runner.StopCoroutine(coroutine);
 }
Ejemplo n.º 11
0
 private void OnValidate()
 {
     if (!_rigidbody)
     {
         _rigidbody = GetComponent <Rigidbody>();
     }
     if (!_rigidbody)
     {
         _rigidbody             = gameObject.AddComponent <Rigidbody>();
         _rigidbody.isKinematic = true;
         ManagedLog.Log($"Added Rigidbody to {name}.", ManagedLog.Type.Info);
     }
 }
Ejemplo n.º 12
0
        private static void InitializeOnLoadMethod()
        {
            ManagedLog.LogMethod(type: ManagedLog.Type.Structure);
            SceneManager.sceneLoaded   += SceneManagerOnSceneLoaded;
            SceneManager.sceneUnloaded += SceneManagerOnSceneUnloaded;

            PlayerLoopUtilities.AppendToPlayerLoop <Update.ScriptRunBehaviourUpdate>(typeof(ManagedLog), OnUpdate);

            // SceneManagerOnSceneLoaded doesn't get called for initial scene in builds, we need to call it on load to capture Managed Objects
            #if !UNITY_EDITOR
            var activeScene = SceneManager.GetActiveScene();
            AddAllManagedObjectsInScene(activeScene);
            #endif
        }
Ejemplo n.º 13
0
        private static void CheckLevelEnterPlayModeForLoadingMainScene()
        {
            if (!ProjectEditorConfig.Instance.AutoTestLevelScenes)
            {
                return;
            }

            // No game exists
            var game = FindAllObjects.InScene <GameBase>().FirstOrDefault();

            if (game)
            {
                return;
            }

            // Found level helper
            var sceneRef = FindAllObjects.InScene <LevelSceneRefBase>();

            if (sceneRef.Length <= 0)
            {
                return;
            }

            ManagedLog.Log($"Loading main scene to test {SceneManager.GetActiveScene().name}");

            var testingScene = AssetDatabase.LoadAssetAtPath <SceneAsset>(SceneManager.GetActiveScene().path);

            GameWindow.TestLevel = AssetDatabase.LoadAssetAtPath <SceneAsset>(SceneManager.GetActiveScene().path);

            _asyncOperation = EditorSceneManager.LoadSceneAsyncInPlayMode(GameWindow.MainSceneAssetPath,
                                                                          new LoadSceneParameters(LoadSceneMode.Single));

            _asyncOperation.completed += OnloadComplete;

            void OnloadComplete(AsyncOperation obj)
            {
                game = FindAllObjects.InScene <GameBase>().FirstOrDefault();
                _asyncOperation.completed -= OnloadComplete;
                Assert.IsNotNull(game);

#if USING_SHAPES
                WorldLog.OnScreen($"Testing {testingScene.name}");
#endif
                new Operation(delay: 1f, action: () =>
                {
                    game.StartGame();
                }).Start();
            }
        }
Ejemplo n.º 14
0
        internal static void RegisterViewOrController(Object obj)
        {
            switch (obj)
            {
            case View view:
                Views.Add(view);
                break;

            case ControllerBase controllerBase:
                Controllers.Add(controllerBase);
                break;

            default:
                return;
            }
            ManagedLog.Log($"Registered new {obj.GetType().Name} ({obj.GetScenePath()})", ManagedLog.Type.Structure);
        }
Ejemplo n.º 15
0
 internal void InternalOnLevelStart(MainSceneRefBase levelData, TLevelSceneRefBase levelSceneRef)
 {
     ManagedLog.Log($"{GetType().Name}.{nameof(InternalOnLevelStart)} ({this.GetScenePath()})",
                    ManagedLog.Type.Verbose);
     OnLevelDidStart(levelData as TMainSceneRefBase, levelSceneRef);
 }
Ejemplo n.º 16
0
 internal void InternalOnLevelStop()
 {
     ManagedLog.Log($"{GetType().Name}.{nameof(InternalOnLevelStop)} ({this.GetScenePath()})",
                    ManagedLog.Type.Verbose);
     OnLevelDidStop();
 }
        // Disabled for now

        /*
         #region Access Restriction
         *
         * // ReSharper disable once InconsistentNaming
         * public new GameObject gameObject
         * {
         *  get
         *  {
         *      Debug.LogWarning($"Shouldn't access {nameof(gameObject)} of {nameof(ControllerBase)}");
         *      return base.gameObject;
         *  }
         * }
         *
         * // ReSharper disable once InconsistentNaming
         * public new Transform transform
         * {
         *  get
         *  {
         *
         *      Debug.LogWarning($"Shouldn't access {nameof(transform)} of {nameof(ControllerBase)}");
         *      return base.transform;
         *  }
         * }
         *
         * // ReSharper disable once InconsistentNaming
         * public new bool enabled
         * {
         *  get
         *  {
         *      Debug.LogWarning($"Shouldn't access {nameof(enabled)} of {nameof(ControllerBase)}");
         *      return base.enabled;
         *  }
         *  set
         *  {
         *      Debug.LogWarning($"Shouldn't access {nameof(enabled)} of {nameof(ControllerBase)}");
         *      base.enabled = value;
         *  }
         * }
         *
         #endregion
         */

        #region Logging Helper Methods

        protected void Log(object obj, ManagedLog.Type type = ManagedLog.Type.Default, Object context = null) => ManagedLog.Log(obj, type, context ? context : this);
 protected void LogMethod(object obj = null, ManagedLog.Type type = ManagedLog.Type.Default, Object context = null) => ManagedLog.LogMethod(obj: obj, type: type, context: context, stackOffset: 1);
Ejemplo n.º 19
0
 private static void LogTimeScale() => ManagedLog.Log($"TimeScale: {Time.timeScale}", avoidFrameCount: true);
Ejemplo n.º 20
0
 private void LogMethodTest()
 {
     ManagedLog.LogMethod();
 }
Ejemplo n.º 21
0
 private static void SceneManagerOnSceneUnloaded(Scene arg0)
 {
     ManagedLog.LogMethod(type: ManagedLog.Type.Structure);
     Views.RemoveAll(view => !view);
     Controllers.RemoveAll(controllerBase => !controllerBase);
 }
Ejemplo n.º 22
0
 // This doesn't get called for initial scene in builds.
 private static void SceneManagerOnSceneLoaded(Scene scene, LoadSceneMode arg1)
 {
     ManagedLog.LogMethod(type: ManagedLog.Type.Structure);
     AddAllManagedObjectsInScene(scene);
     // TODO: We need to keep track of newly instantiated views and destroyed ones
 }
Ejemplo n.º 23
0
 private static void InitializeOnEnterPlayMode()
 {
     ManagedLog.LogMethod(type: ManagedLog.Type.Structure);
     Controllers.Clear();
     Views.Clear();
 }
Ejemplo n.º 24
0
 private static void InitializeOnEnterPlayMode(EnterPlayModeOptions options)
 {
     ManagedLog.LogMethod(type: ManagedLog.Type.Structure);
     StateMachines.Clear();
 }
Ejemplo n.º 25
0
 private static void InitializeOnLoadMethod()
 {
     ManagedLog.LogMethod(type: ManagedLog.Type.Structure);
     EditorSceneManager.activeSceneChangedInEditMode += OnActiveSceneChangedInEditMode;
     InitScene(SceneManager.GetActiveScene());
 }
Ejemplo n.º 26
0
 private static void Log(object msg)
 {
     ManagedLog.LogMethod(msg, color: Colors.PowderBlue, type: ManagedLog.Type.Structure, stackOffset: 1);
 }
Ejemplo n.º 27
0
        private static void InitializeOnLoadMethod()
        {
            ManagedLog.LogMethod(type: ManagedLog.Type.Structure);

            PlayerLoopUtilities.AppendToPlayerLoop <Update.ScriptRunBehaviourUpdate>(typeof(ManagedLog), LateUpdate);
        }