示例#1
0
文件: Dev.cs 项目: natis1/ModCommon
        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));
        }
示例#2
0
        void SetSpawnRandomObjectsV2DataWithName(SpawnRandomObjectsV2Data data, string uniqueName)
        {
            if (data.gameObject == null)
            {
                Dev.Log("Warning: " + uniqueName + "'s prefab is null!");
                return;
            }

            Dev.Log("Added: " + uniqueName + " data to spawnRandomObjectsV2Data!");
            spawnRandomObjectsV2Data.Add(uniqueName, data);
        }
示例#3
0
        void SetAudioClip(AudioClip clip)
        {
            if (clip == null)
            {
                Dev.Log("Warning: audio clip is null!");
                return;
            }

            Dev.Log("Added: " + clip.name + " to audioClips!");
            audioClips.Add(clip.name, clip);
        }
示例#4
0
 static void PrintDebugLine(string label, string line, string componentHeader = "", StreamWriter file = null)
 {
     if (file != null)
     {
         file.WriteLine(componentHeader + @" \" + label + @": " + line);
     }
     else
     {
         Dev.Log(componentHeader + @" \" + label + @": " + line);
     }
 }
示例#5
0
        void SetGameObjectWithName(GameObject go, string uniqueName)
        {
            if (go == null)
            {
                Dev.Log("Warning: " + uniqueName + " is null!");
                return;
            }

            Dev.Log("Added: " + uniqueName + " to gameObjects!");
            gameObjects.Add(uniqueName, go);
        }
示例#6
0
        void SetGameObject(GameObject go)
        {
            if (go == null)
            {
                Dev.Log("Warning: prefab is null!");
                return;
            }

            Dev.Log("Added: " + go.name + " to gameObjects!");
            gameObjects.Add(go.name, go);
        }
示例#7
0
        void SetActorAudioSource(AudioSource source)
        {
            if (source == null)
            {
                Dev.Log("Warning: Actor AudioSource failed to load and is null!");
                return;
            }

            actorAudioSource = source;
            actorAudioSource.transform.SetParent(gameObject.transform);
            actorAudioSource.transform.localPosition = Vector3.zero;
        }
示例#8
0
        protected virtual CollisionDirection GetCollisionAlongCurrentVelocity(LayerMask layer, float timeStep)
        {
            CollisionDirection directionSet = new CollisionDirection();

            Vector2 origin               = gameObject.transform.position;
            Vector2 direction            = body.velocity.normalized;
            float   distanceNextTimeStep = body.velocity.magnitude * timeStep;

            RaycastHit2D raycastHit2D = Physics2D.Raycast(origin, direction, distanceNextTimeStep, layer);

            //we're not going to hit anything
            if (raycastHit2D.collider == null)
            {
                return(directionSet);
            }

            Dev.Log("We're about to hit a wall!");
            float x  = gameObject.transform.position.x;
            float y  = gameObject.transform.position.y;
            float px = raycastHit2D.point.x;
            float py = raycastHit2D.point.y;

            float dx = Mathf.Abs(x - px);
            float dy = Mathf.Abs(y - py);

            //is it an x collision or a y collision?
            if (dx > dy)
            {
                //x collision, hitting left or right from us?
                if (px < x)
                {
                    directionSet.left = true;
                }
                else
                {
                    directionSet.right = true;
                }
            }
            else
            {
                if (py < y)
                {
                    directionSet.below = true;
                }
                else
                {
                    directionSet.above = true;
                }
            }

            return(directionSet);
        }
示例#9
0
        void SetStateMachineValue <D, T>(D dictionary, string name, T value)
            where D : Dictionary <string, T>
            where T : class
        {
            if (value == null)
            {
                Dev.Log("Warning: " + name + " is null!");
                return;
            }

            Dev.Log("Added: " + name + " to dictionary of " + dictionary.GetType().Name + "!");
            dictionary.Add(name, value);
        }
示例#10
0
        protected static void PlayAnimation(tk2dSpriteAnimator tk2dAnimator, string animation)
        {
            Dev.Where();

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

            tk2dAnimator.AnimationCompleted = null;
            tk2dAnimator.Play(animation);
        }
示例#11
0
        public static void WriteObjectSceneHierarchyTree(this GameObject gameObject, System.IO.StreamWriter file, bool writeProperties = false)
        {
            if (gameObject == null)
            {
                return;
            }

            if (file != null)
            {
                file.WriteLine("START =====================================================");
                file.WriteLine("Printing scene hierarchy for game object: " + gameObject.name);
            }
            else
            {
                Dev.Log("START =====================================================");
                Dev.Log("Printing scene hierarchy for game object: " + gameObject.name);
            }

            foreach (Transform t in gameObject.GetComponentsInChildren <Transform>(true))
            {
                string objectNameAndPath = t.gameObject.PrintSceneHierarchyPath();

                if (file != null)
                {
                    file.WriteLine(objectNameAndPath);
                }
                else
                {
                    Dev.Log(objectNameAndPath);
                }

                string componentHeader = "";
                for (int i = 0; i < (objectNameAndPath.Length - t.gameObject.name.Length); ++i)
                {
                    componentHeader += " ";
                }

                GameInspector.PrintObject(gameObject, componentHeader, file);
            }

            if (file != null)
            {
                file.WriteLine("END +++++++++++++++++++++++++++++++++++++++++++++++++++++++");
            }
            else
            {
                Dev.Log("END +++++++++++++++++++++++++++++++++++++++++++++++++++++++");
            }
        }
示例#12
0
 static protected void HideBossTitle(GameObject areaTitleObject)
 {
     //show title
     if (areaTitleObject != null && areaTitleObject.activeInHierarchy)
     {
         foreach (FadeGroup f in areaTitleObject.GetComponentsInChildren <FadeGroup>())
         {
             f.FadeDown();
         }
     }
     else
     {
         Dev.Log(areaTitleObject + " is null! Cannot hide the boss title.");
     }
 }
示例#13
0
        private void OnTriggerEnter2D(Collider2D collision)
        {
            if (monitorFSMStates)
            {
                return;
            }

            bool isPlayer = false;

            foreach (Transform t in collision.gameObject.GetComponentsInParent <Transform>())
            {
                if (t.gameObject == HeroController.instance.gameObject)
                {
                    isPlayer = true;
                    break;
                }
            }

            if (!isPlayer)
            {
                Dev.Log("Something not the player entered us!");
                return;
            }

            Dev.Log("Player entered our wake area! ");

            if (!string.IsNullOrEmpty(fsmName))
            {
                PlayMakerFSM fsm = FSMUtility.LocateFSM(owner, fsmName);

                if (fsm != null && wakeEvents != null)
                {
                    foreach (string s in wakeEvents)
                    {
                        Dev.Log("Sending event! " + s);
                        fsm.SendEvent(s);
                    }
                }
                else
                {
                    Dev.Log("Could not find FSM!");
                }
            }

            //remove this after waking up the enemy
            Destroy(gameObject);
        }
示例#14
0
        //from will be top1,left1,right1,door1,etc...
        public static IEnumerator EnterZone(string name, string enterFrom, string exitTransition, string waitUntilGameObjectIsLoaded = "", List <string> removeList = null)
        {
            Dev.Where();
            //find a source transition
            string currentSceneTransition = GameObject.FindObjectOfType <TransitionPoint>().gameObject.name;
            string currentScene           = GameManager.instance.sceneName;

            //update the last entered
            TransitionPoint.lastEntered = currentSceneTransition;

            Dev.Log("Creating transition");
            GameManager.instance.BeginSceneTransition(new GameManager.SceneLoadInfo
            {
                SceneName          = name,
                EntryGateName      = enterFrom,
                HeroLeaveDirection = new GlobalEnums.GatePosition?(GetGatePosition(exitTransition)),
                EntryDelay         = 0.1f,
                WaitForSceneTransitionCameraFade = true,
                Visualization            = GameManager.SceneLoadVisualizations.Default,
                AlwaysUnloadUnusedAssets = false
            });

            Dev.Log("waitUntilGameObjectIsLoaded??");
            if (!string.IsNullOrEmpty(waitUntilGameObjectIsLoaded))
            {
                while (GameObject.Find(waitUntilGameObjectIsLoaded) == null)
                {
                    yield return(new WaitForEndOfFrame());
                }
            }
            else
            {
                yield return(new WaitForEndOfFrame());
            }
            Dev.Log("Done!");

            if (removeList != null && removeList.Count > 0)
            {
                Scene scene = UnityEngine.SceneManagement.SceneManager.GetSceneByName(name);
                foreach (string s in removeList)
                {
                    GameObject.Destroy(scene.FindGameObject(s));
                }
            }
        }
示例#15
0
 static protected void PlayOneShot(AudioSource source, AudioClip clip, float volume = 1f)
 {
     if (source != null && clip != null)
     {
         source.PlayOneShot(clip, volume);
     }
     else
     {
         if (source == null)
         {
             Dev.Log("Audio source is null! Cannot play sounds.");
         }
         if (clip == null)
         {
             Dev.Log("Audio clip is null! Cannot play sound.");
         }
     }
 }
示例#16
0
        //change the throw to aim at the hero
        protected override IEnumerator CanThrow()
        {
            Dev.Where();

            HeroController hero            = HeroController.instance;
            Vector3        currentPosition = gameObject.transform.position;

            Vector2 throwOrigin = currentPosition;

            float lead = GameRNG.Rand(0f, .2f);

            //aim a bit ahead of our hero
            Vector2 target = hero.GetComponent <Rigidbody2D>().velocity *lead + (Vector2)hero.transform.position;

            //clamp the y prediction so we don't throw into the ground
            if (target.y < throwOrigin.y)
            {
                target.y = throwOrigin.y;
            }

            Vector2 throwDirection = (target - throwOrigin).normalized;

            throwRay     = new Ray(throwOrigin, throwDirection);
            throwRaycast = Physics2D.Raycast(throwOrigin, throwDirection, throwDistance, 1 << 8);
            //Dev.CreateLineRenderer( throwOrigin, throwRaycast.point, Color.white, -2f, .1f );
            //Dev.Log( "ray hit " + throwRaycast.collider.gameObject );

            if (throwRaycast.collider != null && throwRaycast.collider.gameObject != null && throwRaycast.distance < 2f)
            {
                Dev.Log("Target is too close! Skipping throw.");
                Dev.Log("" + throwRaycast.point);

                //TODO: alter this code so that we can throw, but make it shorter and/or have hornet grapple
                //there's a wall, we cannot throw!
                nextState = MoveChoiceB;
            }
            else
            {
                //we can throw!
                nextState = MoveChoiceA;
            }

            yield break;
        }
示例#17
0
        protected override void OnCollisionEnter2D(Collision2D collision)
        {
            base.OnCollisionEnter2D(collision);

            if (isGrappling)
            {
                Dev.Where();
                RaycastHit2D raycast = GetRaycastInDirection(transform.position, (needle.transform.position - transform.position).normalized);
                if (raycast.distance <= (bodyCollider.size.magnitude * raycast.normal).magnitude)
                {
                    OnBoundsCollision(raycast, gameObject, raycast.collider.gameObject);
                }
                else
                {
                    Dev.Log("raycast.distance = " + raycast.distance);
                    Dev.Log("( bodyCollider.size.magnitude * raycast.normal ).magnitude = " + (bodyCollider.size.magnitude * raycast.normal).magnitude);
                }
            }
        }
示例#18
0
 void OnBoundsCollision(RaycastHit2D ray, GameObject self, GameObject other)
 {
     Dev.Where();
     Dev.CreateLineRenderer(transform.position, ray.point, Color.white, -2f, .2f);
     Dev.Log("" + ray.normal);
     if (ray.normal.x < 0f)
     {
         rightHit = true;
     }
     else
     if (ray.normal.x > 0f)
     {
         leftHit = true;
     }
     else//( Mathf.Abs( ray.normal.y ) > .9f )
     {
         topHit = true;
     }
 }
示例#19
0
        protected virtual void RefreshCallbackBindings()
        {
            enabledMethodInfos.Clear();
            enabledCallbacks.Clear();

            // get ALL public, protected, private, and internal methods defined on the node
            var methodInfos = NodeOwner.GetType().GetMethods(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);

            foreach (var methodInfo in methodInfos)
            {
                bool            isReceiverMethod = methodInfo.GetCustomAttributes(true).OfType <CommunicationCallback>().Any();
                ParameterInfo[] parameters       = methodInfo.GetParameters();

                // the method has a [CommunicationCallback] attribute
                if (isReceiverMethod)
                {
                    if (parameters.Length == 1)
                    {
                        //Dev.Log("adding single parameter callback");
                        // the method has a single parameter, the callback binder doesn't expect
                        enabledMethodInfos.Add(new SerializableMethodInfo(methodInfo));
                        enabledCallbacks.Add(parameters[0].ParameterType, methodInfo);
                    }
                    //this method takes two parameters, the 2nd of which is the sending object
                    else if (parameters.Length == 2)
                    {
                        //Dev.Log("adding double parameter callback");
                        // the method has a two parameters, the 2nd is the sending object
                        enabledMethodInfos.Add(new SerializableMethodInfo(methodInfo));
                        enabledCallbacks.Add(parameters[0].ParameterType, methodInfo);
                    }
                    else
                    {
                        Dev.Log("method did not match any callback configuration");
                        //TODO: change to using standard exceptions so we don't have a dependency on debug logging
                        //Debug.LogErrorFormat("{0} is an invalid receiver method!  It must have exactly 1 parameter!", methodInfo.Name);
                        //Dev.Log( methodInfo.Name + "is an invalid receiver method!  It must have exactly 1 parameter!" );
                    }
                }
            }
        }
示例#20
0
        public static List <T> GetFSMActionsOnState <T>(this GameObject gameObject, string stateName, string fsmName = "") where T : HutongGames.PlayMaker.FsmStateAction
        {
            List <T> actions = new List <T>();
            var      state   = gameObject.GetFSMState(stateName, fsmName);

            if (state != null)
            {
                foreach (var action in state.Actions)
                {
                    if (action.GetType() == typeof(T))
                    {
                        actions.Add(action as T);
                    }
                }
            }
            else
            {
                Dev.Log("Warning: No state named " + stateName + "found in fsm " + fsmName);
            }

            return(actions);
        }
示例#21
0
 static protected void PlayOneShotRandom(AudioSource source, List <AudioClip> clip)
 {
     if (source != null && clip != null && clip.Count > 0)
     {
         AudioClip randomClip = clip.GetRandomElementFromList();
         source.PlayOneShot(randomClip);
     }
     else
     {
         if (source == null)
         {
             Dev.Log("Audio source is null! Cannot play sounds.");
         }
         if (clip == null)
         {
             Dev.Log("Audio clip is null! Cannot play sound.");
         }
         if (clip != null && clip.Count <= 0)
         {
             Dev.Log("Audio clip list is empty! No sounds to play.");
         }
     }
 }
示例#22
0
        /*
         * [XmlRoot("AppSettings")]
         * public class ExampleData
         * {
         *  [XmlElement("Data")]
         *  public string data;
         *  [XmlElement("MoreData")]
         *  public string moreData;
         *
         *  [XmlArray("ListOfData")]
         *  public List<string> someListOfData;
         *
         *  [XmlElement(ElementName ="OptionalData", IsNullable = true)]
         *  public bool? someOptionalData;
         * }
         */

        public static bool WriteDataToFile <T>(string path, T settings) where T : class
        {
            bool          result     = false;
            XmlSerializer serializer = new XmlSerializer(typeof(T));
            FileStream    fstream    = null;

            try
            {
                fstream = new FileStream(path, FileMode.Create);
                serializer.Serialize(fstream, settings);
                result = true;
            }
            catch (System.Exception e)
            {
                Dev.Log("Error creating/saving file " + e.Message);
                //System.Windows.Forms.MessageBox.Show("Error creating/saving file "+ e.Message);
            }
            finally
            {
                fstream.Close();
            }
            return(result);
        }
示例#23
0
        private void OnDisable()
        {
            if (monitorFSMStates)
            {
                if (logFSM)
                {
                    Dev.Log("DebugFSMS DebugOnWake was disabled, likely because the enemy died ");
                }

                //final FSM info....
                foreach (var p in owner.GetComponentsInChildren <PlayMakerFSM>())
                {
                    if (p == null)
                    {
                        continue;
                    }

                    if (!fsmsOnObject.ContainsKey(p))
                    {
                        fsmsOnObject.Add(p, p.ActiveStateName);
                        if (logFSM)
                        {
                            Dev.Log("DebugFSMS :::: Added FSM for " + owner.name + " had the fsm [" + p.FsmName + "] with initial state [" + p.ActiveStateName + "]");
                        }
                    }
                    else if (p.ActiveStateName != fsmsOnObject[p])
                    {
                        if (logFSM)
                        {
                            Dev.Log("DebugFSMS :::: " + owner.name + " had the fsm [" + p.FsmName + "] change FROM state [" + fsmsOnObject[p] + "] TO state [" + p.ActiveStateName + "] on EVENT [" + ((p.Fsm != null && p.Fsm.LastTransition != null) ? p.Fsm.LastTransition.EventName : "GAME OBJECT AWAKE") + "]");
                        }
                        fsmsOnObject[p] = p.ActiveStateName;
                    }
                }
            }
        }
示例#24
0
        IEnumerator DebugFSMS()
        {
            fsmsOnObject = new Dictionary <PlayMakerFSM, string>();

            foreach (var p in owner.GetComponentsInChildren <PlayMakerFSM>(true))
            {
                fsmsOnObject.Add(p, p.ActiveStateName);
                if (logFSM)
                {
                    Dev.Log("Added FSM for " + owner.name + " had the fsm [" + p.FsmName + "] with initial state [" + p.ActiveStateName + "]");
                }
            }

            Dev.Where();

            while (monitorFSMStates)
            {
                if (owner == null)
                {
                    yield break;
                }

                foreach (var p in owner.GetComponentsInChildren <PlayMakerFSM>(true))
                {
                    if (p == null)
                    {
                        continue;
                    }

                    if (!fsmsOnObject.ContainsKey(p))
                    {
                        fsmsOnObject.Add(p, p.ActiveStateName);
                        if (logFSM)
                        {
                            Dev.Log("Added FSM for " + owner.name + " had the fsm [" + p.FsmName + "] with initial state [" + p.ActiveStateName + "]");
                        }
                    }
                    else if (p.ActiveStateName != fsmsOnObject[p])
                    {
                        if (logFSM)
                        {
                            Dev.Log("" + owner.name + " had the fsm [" + p.FsmName + "] change FROM state [" + fsmsOnObject[p] + "] TO state [" + p.ActiveStateName + "] on EVENT [" + ((p.Fsm != null && p.Fsm.LastTransition != null) ? p.Fsm.LastTransition.EventName : "GAME OBJECT AWAKE") + "]");
                        }
                        fsmsOnObject[p] = p.ActiveStateName;
                    }

                    //force-send an event on this state if everything matches?
                    if (!string.IsNullOrEmpty(sendWakeEventsOnState) && fsmName == p.FsmName && sendWakeEventsOnState == p.ActiveStateName)
                    {
                        if (p != null && wakeEvents != null)
                        {
                            foreach (string s in wakeEvents)
                            {
                                p.SendEvent(s);
                            }
                        }
                    }
                }

                yield return(new WaitForEndOfFrame());
            }
        }
示例#25
0
 //Taken from Playmaker's SpawnRandomObjectsV2.cs FSM Action
 static protected void DoSpawnRandomObjectsV2(Rigidbody2D body, SpawnRandomObjectsV2Data data)
 {
     try
     {
         float      vectorX        = 0f;
         float      vectorY        = 0f;
         bool       originAdjusted = false;
         GameObject value          = data.gameObject;
         if (value != null)
         {
             Vector3 a    = Vector3.zero;
             Vector3 zero = Vector3.zero;
             if (data.spawnPoint != null)
             {
                 a = data.spawnPoint.transform.position;
                 if (data.position.HasValue)
                 {
                     a += data.position.Value;
                 }
             }
             else if (data.position.HasValue)
             {
                 a = data.position.Value;
             }
             int num = UnityEngine.Random.Range(data.spawnMin.Value, data.spawnMax.Value + 1);
             for (int i = 1; i <= num; i++)
             {
                 GameObject gameObject = UnityEngine.Object.Instantiate <GameObject>(value, a, Quaternion.Euler(zero));
                 float      x          = gameObject.transform.position.x;
                 float      y          = gameObject.transform.position.y;
                 float      z          = gameObject.transform.position.z;
                 if (data.originVariationX != null && data.originVariationX.HasValue)
                 {
                     x = gameObject.transform.position.x + UnityEngine.Random.Range(-data.originVariationX.Value, data.originVariationX.Value);
                     originAdjusted = true;
                 }
                 if (data.originVariationY != null && data.originVariationY.HasValue)
                 {
                     y = gameObject.transform.position.y + UnityEngine.Random.Range(-data.originVariationY.Value, data.originVariationY.Value);
                     originAdjusted = true;
                 }
                 if (originAdjusted)
                 {
                     gameObject.transform.position = new Vector3(x, y, z);
                 }
                 float num2 = UnityEngine.Random.Range(data.speedMin.Value, data.speedMax.Value);
                 float num3 = UnityEngine.Random.Range(data.angleMin.Value, data.angleMax.Value);
                 vectorX = num2 * Mathf.Cos(num3 * 0.0174532924f);
                 vectorY = num2 * Mathf.Sin(num3 * 0.0174532924f);
                 Vector2 velocity;
                 velocity.x    = vectorX;
                 velocity.y    = vectorY;
                 body.velocity = velocity;
             }
         }
     }
     catch (Exception e)
     {
         Dev.Log("Exception: " + e.Source + " " + e.Message + " " + e.StackTrace);
     }
 }
示例#26
0
        /// <summary>
        /// Get the exact value from the action in the state in the fsm. Use the index parameter if there's more than one of the same action in the state. Returns the found value.
        /// Use this to get values that do not require the unity game object to be active.
        /// </summary>
        protected static T GetValueFromAction <T, U>(GameObject go, string fsmName, string stateName, string valueName, int?actionIndex = null)
            where U : FsmStateAction
        {
            List <U> actions = go.GetFSMActionsOnState <U>(stateName, fsmName);

            if (actions == null)
            {
                Dev.Log("Warning: No actions of type " + typeof(U).GetType().Name + " found on state " + stateName + " in fsm " + fsmName);
                return(default(T));
            }

            U action = actions[0];

            if (actionIndex != null && actionIndex.HasValue)
            {
                action = actions[actionIndex.Value];
            }

            FieldInfo fi = action.GetType().GetField(valueName, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);

            if (fi == null)
            {
                Dev.Log(valueName + " not found on action " + action.GetType().Name + " in state " + stateName + " in fsm " + fsmName);

                Dev.Log("Valid valueName's on action: ");

                foreach (FieldInfo f in action.GetType().GetFields(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance))
                {
                    Dev.Log(f.Name);
                }

                return(default(T));
            }

            object fieldValue = fi.GetValue(action);

            T realValue;

            if (fieldValue as FsmObject != null)
            {
                object val = (fieldValue as FsmObject).Value;
                realValue = (T)(val);
            }
            else if (fieldValue as FsmRect != null)
            {
                object val = (fieldValue as FsmRect).Value;
                realValue = (T)(val);
            }
            else if (fieldValue as FsmColor != null)
            {
                object val = (fieldValue as FsmColor).Value;
                realValue = (T)(val);
            }
            else if (fieldValue as FsmEnum != null)
            {
                object val = (fieldValue as FsmEnum).Value;
                realValue = (T)(val);
            }
            else if (fieldValue as FsmArray != null)
            {
                object val = (fieldValue as FsmArray).Values;
                realValue = (T)(val);
            }
            else if (fieldValue as FsmBool != null)
            {
                object val = (fieldValue as FsmBool).Value;
                realValue = (T)(val);
            }
            else if (fieldValue as FsmFloat != null)
            {
                object val = (fieldValue as FsmFloat).Value;
                realValue = (T)(val);
            }
            else if (fieldValue as FsmInt != null)
            {
                object val = (fieldValue as FsmInt).Value;
                realValue = (T)(val);
            }
            else if (fieldValue as FsmMaterial != null)
            {
                object val = (fieldValue as FsmMaterial).Value;
                realValue = (T)(val);
            }
            else if (fieldValue as FsmQuaternion != null)
            {
                object val = (fieldValue as FsmQuaternion).Value;
                realValue = (T)(val);
            }
            else if (fieldValue as FsmString != null)
            {
                object val = (fieldValue as FsmString).Value;
                realValue = (T)(val);
            }
            else if (fieldValue as FsmTexture != null)
            {
                object val = (fieldValue as FsmTexture).Value;
                realValue = (T)(val);
            }
            else if (fieldValue as FsmVector2 != null)
            {
                object val = (fieldValue as FsmVector2).Value;
                realValue = (T)(val);
            }
            else if (fieldValue as FsmVector3 != null)
            {
                object val = (fieldValue as FsmVector3).Value;
                realValue = (T)(val);
            }
            else if (fieldValue as FsmOwnerDefault != null)
            {
                object val = (fieldValue as FsmOwnerDefault).GameObject.Value;
                realValue = (T)(val);
            }
            else if (fieldValue as NamedVariable != null)
            {
                object val = (fieldValue as NamedVariable).RawValue;
                realValue = (T)(val);
            }
            else
            {
                realValue = (T)(fieldValue);
            }


            return(realValue);
        }
示例#27
0
        public static void PrintHierarchy(this Scene scene, int localIndex = -1, Bounds?sceneBounds = null, List <string> randomizerEnemyTypes = null, string outputFileName = "")
        {
            if (!scene.IsValid())
            {
                return;
            }

            System.IO.StreamWriter file = null;
            if (!string.IsNullOrEmpty(outputFileName))
            {
                try
                {
                    file = new System.IO.StreamWriter(Application.dataPath + "/Managed/Mods/" + outputFileName);
                }
                catch (Exception e)
                {
                    Dev.Log("Exception!: " + e.Message);
                    file = null;
                }
            }

            if (file != null)
            {
                file.WriteLine("START =====================================================");
                file.WriteLine("Printing full hierarchy for scene: " + scene.name + " [Build index: " + scene.buildIndex + "]");

                if (localIndex >= 0)
                {
                    file.WriteLine("Local scene index: " + localIndex);
                }
            }
            else
            {
                Dev.Log("START =====================================================");
                Dev.Log("Printing full hierarchy for scene: " + scene.name + " [Build index: " + scene.buildIndex + "]");

                if (localIndex >= 0)
                {
                    Dev.Log("Local scene index: " + localIndex);
                }
            }

            GameObject[] rootGameObjects = scene.GetRootGameObjects();

            try
            {
                foreach (GameObject go in rootGameObjects)
                {
                    if (go == null)
                    {
                        if (file != null)
                        {
                            file.WriteLine("Scene " + scene.name + " has a null root game object! Skipping debug print scene...");
                        }
                        else
                        {
                            Dev.Log("Scene " + scene.name + " has a null root game object! Skipping debug print scene...");
                        }
                        break;
                    }

                    if (string.IsNullOrEmpty(outputFileName))
                    {
                        go.PrintSceneHierarchyTree(true);
                    }
                    else
                    {
                        go.PrintSceneHierarchyTree(true, file);
                    }
                }
            }
            catch (Exception e)
            {
                Dev.Log("Exception: " + e.Message);
            }

            if (file != null)
            {
                file.WriteLine("END +++++++++++++++++++++++++++++++++++++++++++++++++++++++");
                file.Close();
            }
            else
            {
                Dev.Log("END +++++++++++++++++++++++++++++++++++++++++++++++++++++++");
            }
        }
示例#28
0
        IEnumerator Out()
        {
            Dev.Where();

            yield return(new WaitForSeconds(startDelay));

            meshRenderer.enabled = true;

            Vector2 throwVector = throwRay.direction * throwDistance;

            //needle requires a 180 flip to orient properly
            //float angleToTarget = GetAngleToTarget(startPos, throwTarget, 0f, -.5f);
            //transform.rotation = Quaternion.AngleAxis(angleToTarget + 180f, Vector3.forward);

            Dev.Log("Rotation before = " + transform.rotation.eulerAngles);

            //TODO: Testing this
            transform.right = -throwRay.direction;

            Dev.Log("Rotation = " + transform.rotation.eulerAngles);

            //Vector3 throwDirection = ((Vector3)throwTarget + throwRay.origin) - transform.position;
            //if( throwDirection != Vector3.zero )
            //{
            //    float angle = Mathf.Atan2(throwDirection.y, throwDirection.x) * Mathf.Rad2Deg;
            //    transform.rotation = Quaternion.AngleAxis( angle + 180f, Vector3.forward );
            //}

            AnimationCurve throwCurve = new AnimationCurve();

            throwCurve.AddKey(0f, 0f);
            throwCurve.AddKey(.1f, .2f);
            throwCurve.AddKey(.2f, .4f);
            throwCurve.AddKey(.3f, .6f);
            throwCurve.AddKey(.4f, .75f);
            throwCurve.AddKey(.5f, .85f);
            throwCurve.AddKey(.6f, .92f);
            throwCurve.AddKey(.7f, .95f);
            throwCurve.AddKey(.8f, .97f);
            throwCurve.AddKey(.9f, .98f);
            throwCurve.AddKey(1f, 1f);

            float throwTime = throwMaxTravelTime;
            float time      = 0f;

            while (time < throwTime)
            {
                float t = time / throwTime;

                if (t > .1f && canHitWalls && HitWall)
                {
                    break;
                }

                if (t <= .1f)
                {
                    HitWall = false;
                }

                body.position = throwCurve.Evaluate(t) * (Vector3)throwVector + startPos;
                Dev.Log("Rotation = " + transform.rotation.eulerAngles);
                Dev.Log("Animating " + body.position);

                time += Time.fixedDeltaTime;
                yield return(new WaitForFixedUpdate());
            }

            Dev.Log("canHitWalls" + canHitWalls);
            Dev.Log("HitWall" + HitWall);
            if (canHitWalls && HitWall)
            {
                currentState = CompleteFromHitWall();
            }
            else
            {
                currentState = Return();
            }

            yield break;
        }
示例#29
0
        public static void PrintSceneHierarchyTree(this GameObject gameObject, bool printComponents = false, System.IO.StreamWriter file = null)
        {
            if (gameObject == null)
            {
                return;
            }

            if (file != null)
            {
                file.WriteLine("START =====================================================");
                file.WriteLine("Printing scene hierarchy for game object: " + gameObject.name);
            }
            else
            {
                Dev.Log("START =====================================================");
                Dev.Log("Printing scene hierarchy for game object: " + gameObject.name);
            }

            foreach (Transform t in gameObject.GetComponentsInChildren <Transform>(true))
            {
                string objectNameAndPath = t.gameObject.PrintSceneHierarchyPath();

                if (file != null)
                {
                    file.WriteLine(objectNameAndPath);
                }
                else
                {
                    Dev.Log(objectNameAndPath);
                }


                if (printComponents)
                {
                    string componentHeader = "";
                    for (int i = 0; i < (objectNameAndPath.Length - t.gameObject.name.Length); ++i)
                    {
                        componentHeader += " ";
                    }

                    foreach (Component c in t.GetComponents <Component>())
                    {
                        c.PrintComponentType(componentHeader, file);
                        c.PrintTransform(componentHeader, file);
                        c.PrintBoxCollider2D(componentHeader, file);
                        c.PrintCircleCollider2D(componentHeader, file);
                        c.PrintPolygonCollider2D(componentHeader, file);
                        c.PrintRigidbody2D(componentHeader, file);
                        c.PrintPersistentBoolItem(componentHeader, file);
                        c.PrintPlayMakerFSM(componentHeader, file);
                    }
                }
            }

            if (file != null)
            {
                file.WriteLine("END +++++++++++++++++++++++++++++++++++++++++++++++++++++++");
            }
            else
            {
                Dev.Log("END +++++++++++++++++++++++++++++++++++++++++++++++++++++++");
            }
        }