Example #1
0
        public static bool ReadDataFromFile <T>(string path, out T settings) where T : class
        {
            settings = null;

            if (!File.Exists(path))
            {
                //System.Windows.Forms.MessageBox.Show("No file found at " + path );
                return(false);
            }

            bool returnResult = true;

            XmlSerializer serializer = new XmlSerializer(typeof(T));
            FileStream    fstream    = null;

            try
            {
                fstream  = new FileStream(path, FileMode.Open);
                settings = serializer.Deserialize(fstream) as T;
            }
            catch (System.Exception e)
            {
                Dev.Log("Error loading file " + e.Message);
                //System.Windows.Forms.MessageBox.Show("Error loading file " + e.Message);
                returnResult = false;
            }
            finally
            {
                fstream.Close();
            }

            return(returnResult);
        }
Example #2
0
        protected virtual IEnumerator MainAILoop()
        {
            Dev.Where();

            for (;;)
            {
                if (!Running)
                {
                    break;
                }

                yield return(currentState);

                if (nextState != null)
                {
                    //TODO: remove as the states get implemented
                    //Dev.Log( "State Complete - Hit N to advance" );
                    //while( !Input.GetKeyDown( KeyCode.N ) )
                    //{
                    //    yield return new WaitForEndOfFrame();
                    //}
                    //Dev.Log( "Next" );
                    if (overrideNextState != null)
                    {
                        nextState         = overrideNextState;
                        overrideNextState = null;
                    }

                    currentState = nextState();
                    nextState    = null;
                }
            }

            yield break;
        }
Example #3
0
        IEnumerator MainAILoop()
        {
            Dev.Where();

            for (; ;)
            {
                yield return(new WaitForEndOfFrame());

                if (stuns >= maxStuns)
                {
                    break;
                }

                if (isSuspended)
                {
                    continue;
                }

                if (hitsTaken < hitsToStun)
                {
                    continue;
                }

                yield return(Stun());
            }

            this.enabled = false;
        }
Example #4
0
 //copied and modified from "TransitionPoint.cs"
 public static GlobalEnums.GatePosition GetGatePosition(string name)
 {
     if (name.Contains("top"))
     {
         return(GlobalEnums.GatePosition.top);
     }
     if (name.Contains("right"))
     {
         return(GlobalEnums.GatePosition.right);
     }
     if (name.Contains("left"))
     {
         return(GlobalEnums.GatePosition.left);
     }
     if (name.Contains("bot"))
     {
         return(GlobalEnums.GatePosition.bottom);
     }
     if (name.Contains("door"))
     {
         return(GlobalEnums.GatePosition.door);
     }
     Dev.LogError("Gate name " + name + "does not conform to a valid gate position type. Make sure gate name has the form 'left1'");
     return(GlobalEnums.GatePosition.unknown);
 }
Example #5
0
        static string GetFunctionHeader(int frame = 0)
        {
            //get stacktrace info
            StackTrace stackTrace = new StackTrace();
            string     class_name = stackTrace.GetFrame(BaseFunctionHeader + frame).GetMethod().ReflectedType.Name;

            //build parameters string
            System.Reflection.ParameterInfo[] parameters = stackTrace.GetFrame(3 + frame).GetMethod().GetParameters();
            string parameters_name = "";
            bool   add_comma       = false;

            foreach (System.Reflection.ParameterInfo parameter in parameters)
            {
                if (add_comma)
                {
                    parameters_name += ", ";
                }

                parameters_name += Dev.Colorize(parameter.ParameterType.Name, _param_color);
                parameters_name += " ";
                parameters_name += Dev.Colorize(parameter.Name, _log_color);

                add_comma = true;
            }

            //build function header
            string function_name = stackTrace.GetFrame(BaseFunctionHeader + frame).GetMethod().Name + "(" + parameters_name + ")";

            return(class_name + "." + function_name);
        }
Example #6
0
        private IEnumerator Start()
        {
            Dev.Where();
            while (owner == null)
            {
                yield return(null);
            }

            if (logFSM)
            {
                if (collider != null)
                {
                    lines = new List <GameObject>();
                    lines = Dev.CreateBoxOfLineRenderers(collider.bounds, Color.green, -2.1f, .01f);
                    foreach (var go in lines)
                    {
                        go.transform.SetParent(owner.transform);
                        go.transform.localPosition = Vector3.zero;
                    }
                }
            }

            if (monitorFSMStates)
            {
                StartCoroutine(DebugFSMS());
            }
        }
Example #7
0
        ///get the farther of the two collision points along the given rays. Null raycastMask defaults to the ground collision layer (8)
        static protected RaycastHit2D?GetRaycastWithMaxDistance(Vector2 origin, Vector2 directionA, Vector2 directionB, LayerMask?raycastMask = null)
        {
            RaycastHit2D testRaycastA = GetRaycastInDirection(origin, directionA, raycastMask);
            RaycastHit2D testRaycastB = GetRaycastInDirection(origin, directionB, raycastMask);

            if (testRaycastA.collider == null && testRaycastB.collider == null)
            {
                //error!
                Dev.LogError("Both raycasts returned null! Collision point was found in either direction! (Likely a bad layermask or origin point)");
                return(null);
            }
            else if (testRaycastA.collider == null)
            {
                return(testRaycastB);
            }
            else if (testRaycastB.collider == null)
            {
                return(testRaycastA);
            }

            if (testRaycastA.distance > testRaycastB.distance)
            {
                return(testRaycastA);
            }
            return(testRaycastB);
        }
Example #8
0
        IEnumerator Init()
        {
            Dev.Where();

            meshRenderer.enabled = true;

            transform.localPosition = new Vector3(0f, 0f, 0f);

            transform.localRotation = Quaternion.identity;

            Vector3 localScale = transform.localScale;
            Vector3 lossyScale = transform.lossyScale;

            transform.SetParent(null);

            transform.localScale = lossyScale;

            yield return(PlayFromFrameAndWaitForEndOfAnimation(0));

            isAnimating = false;

            transform.SetParent(parent.transform);

            transform.localScale = localScale;

            meshRenderer.enabled = false;

            currentState = null;

            gameObject.SetActive(false);

            yield break;
        }
Example #9
0
        /// <summary>
        /// Iterate through all the scenes in the game in a breadth-first search style. For each scene, the provided onVisit method will be called.
        /// ------
        /// onVisit is a callback that takes:
        /// MapNode current (node being visited)
        /// MapNode previous (node last visited)
        /// Dictionary<string, MapNode> visited (set of visited nodes)
        /// Dictionary<string, MapNode> map (the entire map)
        /// </summary>
        /// <returns></returns>
        public IEnumerator DoLoad(string startScene, Func <MapNode, MapNode, Dictionary <string, MapNode>, Dictionary <string, MapNode>, IEnumerator> onVisit)
        {
            if (map.Count <= 0)
            {
                //build the map
                BuildMap();
            }

            remaining = new Dictionary <string, MapNode>(map);

            if (!map.ContainsKey(startScene))
            {
                Dev.LogError("Scene " + startScene + " not found in game map!");
                yield break;
            }

            MapNode current = null;
            MapNode prev    = null;

            pending.Enqueue(map[startScene]);

            do
            {
                prev    = current;
                current = pending.Dequeue();
                yield return(onVisit(current, prev, visited, map));

                AddNeighborsToQueue(current);
                visited.Add(current.scene.SceneName, current);
            }while(pending.Count > 0);
        }
Example #10
0
        public static GameObject FindGameObject(this Scene scene, string name)
        {
            if (!scene.IsValid())
            {
                return(null);
            }

            GameObject[] rootGameObjects = scene.GetRootGameObjects();

            try
            {
                foreach (GameObject go in rootGameObjects)
                {
                    if (go == null)
                    {
                        break;
                    }

                    GameObject found = go.FindGameObjectInChildren(name);
                    if (found != null)
                    {
                        return(found);
                    }
                }
            }
            catch (Exception e)
            {
                Dev.Log("Exception: " + e.Message);
            }

            return(null);
        }
Example #11
0
        static protected void ShowBossTitle(MonoBehaviour owner, GameObject areaTitleObject, float hideInSeconds, string largeMain = "", string largeSuper = "", string largeSub = "", string smallMain = "", string smallSuper = "", string smallSub = "")
        {
            //show hornet title
            if (areaTitleObject != null)
            {
                areaTitleObject.SetActive(true);
                foreach (FadeGroup f in areaTitleObject.GetComponentsInChildren <FadeGroup>())
                {
                    f.FadeUp();
                }

                //TODO: add an offset to the positions and separate this into 2 functions, one for the big title and one for the small title
                areaTitleObject.FindGameObjectInChildren("Title Small Main").GetComponent <Transform>().Translate(new Vector3(4f, 0f, 0f));
                areaTitleObject.FindGameObjectInChildren("Title Small Sub").GetComponent <Transform>().Translate(new Vector3(4f, 0f, 0f));
                areaTitleObject.FindGameObjectInChildren("Title Small Super").GetComponent <Transform>().Translate(new Vector3(4f, 0f, 0f));

                areaTitleObject.FindGameObjectInChildren("Title Small Main").GetComponent <TMPro.TextMeshPro>().text  = smallMain;
                areaTitleObject.FindGameObjectInChildren("Title Small Sub").GetComponent <TMPro.TextMeshPro>().text   = smallSub;
                areaTitleObject.FindGameObjectInChildren("Title Small Super").GetComponent <TMPro.TextMeshPro>().text = smallSuper;

                areaTitleObject.FindGameObjectInChildren("Title Large Main").GetComponent <TMPro.TextMeshPro>().text  = largeMain;
                areaTitleObject.FindGameObjectInChildren("Title Large Sub").GetComponent <TMPro.TextMeshPro>().text   = largeSub;
                areaTitleObject.FindGameObjectInChildren("Title Large Super").GetComponent <TMPro.TextMeshPro>().text = largeSuper;

                if (hideInSeconds > 0f)
                {
                    //give it 3 seconds to fade in
                    owner.StartCoroutine(GameStateMachine.HideBossTitleAfter(areaTitleObject, hideInSeconds + 3f));
                }
            }
            else
            {
                Dev.Log(areaTitleObject + " is null! Cannot show the boss title.");
            }
        }
Example #12
0
        protected virtual IEnumerator PlayAndWaitForEndOfAnimation(tk2dSpriteAnimator tk2dAnimator, string animation, Action doWhileWaiting = null)
        {
            Dev.Where();

            if (tk2dAnimator.GetClipByName(animation) == null)
            {
                Dev.Log("Warning: " + animation + " clip not found");
                yield break;
            }

            tk2dAnimator.AnimationCompleted = OnAnimationComplete;
            tk2dAnimator.Play(animation);

            BlockingAnimationIsPlaying = true;

            while (BlockingAnimationIsPlaying)
            {
                if (doWhileWaiting != null)
                {
                    doWhileWaiting.Invoke();
                }

                yield return(new WaitForEndOfFrame());
            }
            yield break;
        }
Example #13
0
 protected virtual void SetStateMachineValue <T>(T value)
 {
     if (value as AudioClip != null)
     {
         var v = value as AudioClip;
         SetStateMachineValue(audioClips, v.name, v);
     }
     else if (value as ParticleSystem != null)
     {
         var v = value as ParticleSystem;
         SetStateMachineValue(particleSystems, v.name, v);
     }
     else if (value as GameObject != null)
     {
         var v = value as GameObject;
         SetStateMachineValue(gameObjects, v.name, v);
     }
     else
     {
         if (value != null)
         {
             Dev.Log("Warning: No handler defined for SetStateMachineValue for type " + value.GetType().Name);
         }
         else
         {
             Dev.Log("Warning: value is null!");
         }
     }
 }
Example #14
0
        public static void Log(string text, Color color)
        {
#if UNITY_EDITOR && !DISABLE_EDITOR_DEBUG
            UnityEngine.Debug.Log(Dev.FunctionHeader() + Dev.Colorize(text, Dev.ColorToHex(color)));
#else
            DevLoggingOutput.Instance.Log(Dev.FunctionHeader() + Dev.Colorize(text, Dev.ColorToHex(color)));
#endif
        }
Example #15
0
        IEnumerator Complete()
        {
            Dev.Where();

            Stop();

            yield break;
        }
Example #16
0
        public static void Where()
        {
#if UNITY_EDITOR && !DISABLE_EDITOR_DEBUG
            UnityEngine.Debug.Log(" :::: " + Dev.FunctionHeader());
#else
            DevLoggingOutput.Instance.Log(" :::: " + Dev.FunctionHeader());
#endif
        }
Example #17
0
        protected virtual IEnumerator GLeft()
        {
            Dev.Where();

            nextState = Left;

            yield break;
        }
Example #18
0
        public static void Log(string text, float r, float g, float b)
        {
#if UNITY_EDITOR && !DISABLE_EDITOR_DEBUG
            UnityEngine.Debug.Log(Dev.FunctionHeader() + Dev.Colorize(text, Dev.ColorStr(r, g, b)));
#else
            DevLoggingOutput.Instance.Log(Dev.FunctionHeader() + Dev.Colorize(text, Dev.ColorStr(r, g, b)));
#endif
        }
Example #19
0
        protected virtual IEnumerator GRight()
        {
            Dev.Where();

            nextState = Right;

            yield break;
        }
Example #20
0
        protected virtual IEnumerator HitWall()
        {
            Dev.Where();


            nextState = CheckOnGround;

            yield break;
        }
Example #21
0
        protected virtual IEnumerator EnterVelocity()
        {
            Dev.Where();


            nextState = Dashing;

            yield break;
        }
Example #22
0
        //switch to this state when we enter from a transition
        protected virtual IEnumerator EnterSuperDash()
        {
            Dev.Where();

            nextState = EnterL;
            nextState = EnterR;

            yield break;
        }
Example #23
0
        protected virtual IEnumerator DirectionWall()
        {
            Dev.Where();

            nextState = Right;
            nextState = Left;

            yield break;
        }
Example #24
0
        protected virtual IEnumerator WallCharged()
        {
            Dev.Where();


            nextState = DirectionWall;

            yield break;
        }
Example #25
0
        protected virtual IEnumerator ChargeCancelWall()
        {
            Dev.Where();


            nextState = RegainControl;

            yield break;
        }
Example #26
0
 //Example of using a non-generic function to get a value from GetValueFromAction
 protected virtual void SetAudioSource(AudioSource value)
 {
     if (value == null)
     {
         Dev.Log("Warning: SetAudioSource is null!");
         return;
     }
     actorAudioSource = value;
 }
Example #27
0
        protected virtual IEnumerator DashStart()
        {
            Dev.Where();


            nextState = CheckOnGround;

            yield break;
        }
Example #28
0
        protected virtual IEnumerator Left()
        {
            Dev.Where();


            nextState = DashStart;

            yield break;
        }
Example #29
0
        protected virtual IEnumerator RegainControl()
        {
            Dev.Where();

            hero.RegainControl();

            nextState = Inactive;

            yield break;
        }
Example #30
0
        public static GameObject CreateLineRenderer(Vector2 from, Vector2 to, Color c, float z = 0f, float width = .5f)
        {
            Dev.Log("Creating line renderer from " + from + " to " + to);
            List <Vector2> points = new List <Vector2>()
            {
                from, to
            };

            return(points.CreateLineRenderer(c, z, width));
        }