コード例 #1
0
ファイル: MAnimalLogic.cs プロジェクト: mkinahan/Moonman
        void Awake()
        {
            if (Anim == null)
            {
                Anim = GetComponentInParent <Animator>();                //Cache the Animator
            }
            if (RB == null)
            {
                RB = GetComponentInParent <Rigidbody>();                 //Catche the Rigid Body
            }
            if (MainCamera == null)
            {
                MainCamera = MTools.FindMainCamera()?.transform;         //Find the Camera
            }
            if (Rotator != null && RootBone == null)
            {
                RootBone = Rotator.GetChild(0);           //Find the First Rotator Child  THIS CAUSE ISSUES WITH TIMELINE!!!!!!!!!!!!
            }
            GetHashIDs();

            foreach (var set in speedSets)
            {
                set.CurrentIndex = set.StartVerticalIndex;
            }

            if (RB)
            {
                RB.useGravity  = false;
                RB.constraints = RigidbodyConstraints.FreezeRotation;
            }

            GetAnimalColliders();

            for (int i = 0; i < states.Count; i++)
            {
                if (states[i] != null)
                {
                    if (CloneStates)
                    {
                        State instance = (State)ScriptableObject.CreateInstance(states[i].GetType());
                        instance      = ScriptableObject.Instantiate(states[i]);                            //Create a clone from the Original Scriptable Objects! IMPORTANT
                        instance.name = instance.name.Replace("(Clone)", "(C)");
                        states[i]     = instance;
                    }

                    //statesD.Add(states[i].ID.ID, states[i]);        //Convert it to a Dictionary

                    states[i].SetAnimal(this);                                          //Awake all States
                    states[i].Priority = states.Count - i;
                    states[i].AwakeState();
                }
            }



            //Awake all modes
            for (int i = 0; i < modes.Count; i++)
            {
                modes[i].Priority = modes.Count - i;
                modes[i].AwakeMode(this);
            }

            SetPivots();
            CalculateHeight();

            currentSpeedSet = new MSpeedSet()
            {
                Speeds = new List <MSpeed>(1)
                {
                    new MSpeed("Default", 1, 4, 4)
                }
            };                                                                                                     //Create a Default Speed at Awake


            AlignUniqueID = UnityEngine.Random.Range(0, 99999);
        }