コード例 #1
0
    public static List <string> GetAllStateNames(GameObject gameObject, int layer)
    {
        var animator            = (gameObject as GameObject).GetComponent <Animator>();
        var availableStateNames = new List <string>();

        if (animator.runtimeAnimatorController is UnityEditor.Animations.AnimatorController)
        {
            var ac = animator.runtimeAnimatorController as UnityEditor.Animations.AnimatorController;
            var sm = ac.layers[layer].stateMachine;
            for (int i = 0; i < sm.states.Length; i++)
            {
                UnityEditor.Animations.AnimatorState state = sm.states[i].state;
                var stateName = state.name;
                availableStateNames.Add(stateName);
            }
        }
        else if (animator.runtimeAnimatorController is UnityEngine.AnimatorOverrideController)
        {
            var aoc = animator.runtimeAnimatorController as UnityEngine.AnimatorOverrideController;
            aoc.animationClips.ToList().ForEach(animationClip => availableStateNames.Add(animationClip.name));
        }
        else //if(animator.runtimeAnimatorController!=null)
        {
            animator.runtimeAnimatorController.animationClips.ToList().ForEach(animationClip => availableStateNames.Add(animationClip.name));
        }
        // else
        {
            //    Debug.LogError("AnimatorController Type not supported");
        }

        return(availableStateNames);
    }
コード例 #2
0
    private static UnityEditor.Animations.AnimatorState AddStateTransition(UnityEditor.Animations.AnimatorController animatorController, string path, UnityEditor.Animations.AnimatorControllerLayer layer)
    {
        ////根据动画文件读取它的AnimationClip对象
        AnimationClip newClip = null;

        if (File.Exists(path))
        {
            newClip = AssetDatabase.LoadAssetAtPath(path, typeof(AnimationClip)) as AnimationClip;
        }
        string[] sL    = Path.GetFileName(path).Split(".".ToCharArray());
        string   aName = sL[0];

        UnityEngine.AnimatorControllerParameter p = new UnityEngine.AnimatorControllerParameter();
        p.type        = UnityEngine.AnimatorControllerParameterType.Bool;
        p.name        = aName;
        p.defaultBool = false;
        animatorController.AddParameter(p);


        ////取出动画名子 添加到state里面
        UnityEditor.Animations.AnimatorState state = layer.stateMachine.AddState(aName);
        if (newClip != null)
        {
            state.motion = newClip;
        }

        return(state);

        //把state添加在layer里面
        //UnityEditor.Animations.AnimatorStateTransition ts = sm.AddAnyStateTransition(state);
    }
コード例 #3
0
    private static void EnumStatesImp(Animator animator, ref Hashtable statedic, UnityEditor.Animations.AnimatorStateMachine sm)
    {
        int stateCount = sm.states.Length;

        for (int i = 0; i < stateCount; i++)
        {
            UnityEditor.Animations.AnimatorState state = sm.states[i].state;
            if (state != null)
            {
                string statename = state.name;
                if (statename == null)
                {
                    continue;
                }

                statedic[statename] = state;
            }
        }

        int stateMachineCount = sm.stateMachines.Length;

        for (int i = 0; i < stateMachineCount; i++)
        {
            UnityEditor.Animations.AnimatorStateMachine childsm = sm.stateMachines[i].stateMachine;
            if (childsm != null)
            {
                EnumStatesImp(animator, ref statedic, childsm);
            }
        }
    }
コード例 #4
0
    private void CreateStateMachine()
    {
        if (avatarPreview == null || avatarPreview.Animator == null)
        {
            return;
        }

        if (controller == null)
        {
            controller = new UnityEditor.Animations.AnimatorController();
            controller.AddLayer("preview");
            controller.hideFlags = HideFlags.DontSave;

            //stateMachine = controller.GetLayer(0).stateMachine;
            CreateParameters();

            state = stateMachine.AddState("preview");
            state.SetMotion(previewedMotion);
            state.iKOnFeet  = avatarPreview.IKOnFeet;
            state.hideFlags = HideFlags.DontSave;

            UnityEditor.Animations.AnimatorController.SetAnimatorController(avatarPreview.Animator, controller);
        }

        //if (UnityEditor.Animations.AnimatorController.GetEffectiveAnimatorController(avatarPreview.Animator) != this.controller)
        //{
        //	UnityEditor.Animations.AnimatorController.SetAnimatorController(avatarPreview.Animator, this.controller);
        //}
    }
コード例 #5
0
    void DrawControllerPanel()
    {
        GUILayout.BeginVertical(GUILayout.Width(200));

        // controller to add field.
        GUILayout.BeginHorizontal(); {
            controllerToAdd = EditorGUILayout.ObjectField(controllerToAdd, typeof(UnityEditor.Animations.AnimatorController), false) as UnityEditor.Animations.AnimatorController;

            EditorGUI.BeginDisabledGroup(controllerToAdd == null);

            if (GUILayout.Button("Add", GUILayout.ExpandWidth(true), GUILayout.Height(16)))
            {
                eventInspector.AddController(controllerToAdd);
            }

            EditorGUI.EndDisabledGroup();

            //GUILayout.Button("Del", EditorStyles.toolbarButton, GUILayout.Width(38), GUILayout.Height(16));

            GUILayout.Space(4);
        }
        GUILayout.EndHorizontal();

        // controller list

        GUILayout.BeginVertical("Box");
        controllerPanelScrollPos = GUILayout.BeginScrollView(controllerPanelScrollPos);

        UnityEditor.Animations.AnimatorController[] controllers = eventInspector.GetControllers();

        string [] controllerNames = new string[controllers.Length];

        for (int i = 0; i < controllers.Length; i++)
        {
            controllerNames[i] = controllers[i].name;
        }

        selectedController = GUILayout.SelectionGrid(selectedController, controllerNames, 1);

        if (selectedController >= 0 && selectedController < controllers.Length)
        {
            targetController = controllers[selectedController];

            eventInspector.SaveLastEditController(targetController);
        }
        else
        {
            targetController   = null;
            targetStateMachine = null;
            targetState        = null;
            targetEvent        = null;
        }


        GUILayout.EndScrollView();
        GUILayout.EndVertical();


        GUILayout.EndVertical();
    }
コード例 #6
0
 private UnityEditor.Animations.AnimatorState[] GetStates(UnityEditor.Animations.AnimatorStateMachine sm)
 {
     UnityEditor.Animations.AnimatorState[] array = new UnityEditor.Animations.AnimatorState[0];
     //for (int i = 0; i < sm.stateCount; i++)
     //{
     //array[i] = sm.GetState(i);
     //}
     return(array);
 }
コード例 #7
0
    private void FixPositions(GameObject gameObj, float deltaScaleX, float deltaScaleY)
    {
        Vector3 newPos = gameObj.transform.localPosition;

        newPos.x *= deltaScaleX;
        newPos.y *= deltaScaleY;
        gameObj.transform.localPosition = newPos;

        // fix Animation components
        Animation[] animations = gameObj.GetComponents <Animation>();
        foreach (Animation animation in animations)
        {
            foreach (AnimationState animState in animation)
            {
                if (animState.clip != null)
                {
                    this.FixAnimationClip(animState.clip, deltaScaleX, deltaScaleY);
                }
            }
        }

        // fix Animator components
        Animator[] animators = gameObj.GetComponents <Animator>();
        foreach (Animator animator in animators)
        {
            UnityEditor.Animations.AnimatorController animController = animator.runtimeAnimatorController as UnityEditor.Animations.AnimatorController;
        #if UNITY_5_PLUS
            for (int i = 0; i < animController.layers.Length; i++)
        #else
            for (int i = 0; i < animator.layerCount; i++)
        #endif
            {
            #if UNITY_5_PLUS
                UnityEditor.Animations.AnimatorStateMachine stateMachine = animController.layers[i].stateMachine;
                for (int j = 0; j < stateMachine.states.Length; j++)
            #else
                UnityEditor.Animations.AnimatorStateMachine stateMachine = animController.GetLayer(i).stateMachine;
                for (int j = 0; j < stateMachine.stateCount; j++)
            #endif
                {
                #if UNITY_5_PLUS
                    UnityEditor.Animations.ChildAnimatorState state = stateMachine.states[j];
                    Motion mtn = state.state.motion;
                #else
                    UnityEditor.Animations.AnimatorState state = stateMachine.GetState(j);
                    Motion mtn = state.GetMotion();
                #endif

                    if (mtn != null)
                    {
                        AnimationClip clip = mtn as AnimationClip;
                        this.FixAnimationClip(clip, deltaScaleX, deltaScaleY);
                    }
                }
            }
        }
    }
コード例 #8
0
        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            //TODO change to obtain controller thru property.serializedObject.Find(attribute.animator)....
                        UnityEditor.Animations.AnimatorController animatorController = ((MonoBehaviour)property.serializedObject.targetObject).GetComponent<Animator> ().runtimeAnimatorController as UnityEditor.Animations.AnimatorController;

                        if (animatorController != null) {

                                        animatorStateValues = MecanimUtility.GetAnimatorStates (animatorController);
                                        displayOptions = MecanimUtility.GetDisplayOptions (animatorController);

                                EditorGUI.indentLevel = 0;

                                //if already have been serialzied before
                                if(property.objectReferenceValue!=null){

                                    if(animatorStateValues.Length>0){
                                        animatorStateSelected=animatorStateValues.FirstOrDefault((itm)=>itm.nameHash==((ws.winx.unity.AnimatorState)property.objectReferenceValue).nameHash) as UnityEditor.Animations.AnimatorState;
                                    }
                                }

                                //animaStateInfoSelected = property.objectReferenceValue as UnityEditor.Animations.AnimatorState;

                                //EditorGUI.BeginProperty (position, label, property);
                                // Check if it was modified this frame, to avoid overwriting the property constantly
                                EditorGUI.BeginChangeCheck ();
                                animatorStateSelected = EditorGUILayoutEx.CustomObjectPopup (label, animatorStateSelected, displayOptions, animatorStateValues,null, null, null, null, position) as UnityEditor.Animations.AnimatorState;

                                if(EditorGUI.EndChangeCheck() && animatorStateSelected!=null){

                                 	ws.winx.unity.AnimatorState state=property.objectReferenceValue as ws.winx.unity.AnimatorState;
                                    if(state==null) state=ScriptableObject.CreateInstance<ws.winx.unity.AnimatorState>();

                                    state.motion=animatorStateSelected.motion;
                                    state.nameHash=animatorStateSelected.nameHash;

                                    if(state.motion is UnityEditor.Animations.BlendTree){
                                        BlendTree tree =(BlendTree)state.motion;
                                        int blendParamsNum= tree.GetRecursiveBlendParamCount();

                                        state.blendParamsHashes=new int[blendParamsNum];

                                            for(int i=0;i<blendParamsNum;i++)
                                                state.blendParamsHashes[i]=Animator.StringToHash(tree.GetRecursiveBlendParam(i));

                                    }else{

                                        state.blendParamsHashes=null;
                                    }

                                }

                                property.serializedObject.ApplyModifiedProperties ();

                        }
        }
コード例 #9
0
    // Constructor, assign all properties
    public myAni(Animator ani)
    {
        animator = ani;
        Debug.Log(animator.name + " initializing ");
        if (animator.runtimeAnimatorController == null)
        {
            ac = null;
            return;
        }
        ac = animator.runtimeAnimatorController as UnityEditor.Animations.AnimatorController;

        Debug.Log("No. of Layers in **" + ac.name + "** is " + ac.layers.Length);
        for (int h = 0; h < ac.layers.Length; h++)
        {
            lengthOfList += ac.layers [h].stateMachine.states.Length;
        }

        if (ani != null && ac != null)
        {
            mylist         = new string[lengthOfList];
            mylistduration = new float[lengthOfList];
            myclips        = new AnimationClip[lengthOfList];
            int i = 0;

            for (int h = 0; h < ac.layers.Length; h++)
            {
                foreach (UnityEditor.Animations.ChildAnimatorState st in ac.layers[h].stateMachine.states)
                {
                    mylist [i] = st.state.name;

                    //duration
                    for (int k = 0; k < ac.layers[h].stateMachine.states.Length; k++)
                    {
                        UnityEditor.Animations.AnimatorState state = ac.layers [h].stateMachine.states [k].state;
                        if (state.name == mylist [i])
                        {
                            AnimationClip clip = state.motion as AnimationClip;
                            if (clip != null)
                            {
                                mylistduration [i] = clip.length;
                                myclips [i]        = clip;
                            }
                        }
                    }
                    //
                    i++;
                }
            }
            mylistbool = new bool[lengthOfList];
            for (int j = 0; j < lengthOfList; j++)
            {
                mylistbool [j] = false;
            }
        }
    }
コード例 #10
0
    public static AnimatorState[] GetStates(Animator animator, int layer = 0)
    {
        ChildAnimatorState[] childStates = ((UnityEditor.Animations.AnimatorController)animator.runtimeAnimatorController).layers[layer].stateMachine.states;
        UnityEditor.Animations.AnimatorState[] animatorStates = new UnityEditor.Animations.AnimatorState[childStates.Length];

        for (int i = 0; i < childStates.Length; i++)
        {
            animatorStates[i] = childStates[i].state;
        }
        return(animatorStates);
    }
コード例 #11
0
ファイル: UAnimatorState.cs プロジェクト: c-c-c-c/vaTest
 public void SetPushUndo(UnityEditor.Animations.AnimatorState animatorState, bool flag)
 {
     if (animatorState == null)
     {
         return;
     }
     if (dg_set_pushUndo == null || dg_set_pushUndo.Target != (object)animatorState)
     {
         dg_set_pushUndo = (Action <bool>)Delegate.CreateDelegate(typeof(Action <bool>), animatorState, animatorState.GetType().GetProperty("pushUndo", BindingFlags.NonPublic | BindingFlags.Instance).GetSetMethod(true));
     }
     dg_set_pushUndo(flag);
 }
コード例 #12
0
    public static AnimatorState AddState(string sateName, AnimationClip Motion, Animator animator, int layerId = 0)
    {
        UnityEditor.Animations.AnimatorController animatorInternal = (UnityEditor.Animations.AnimatorController)animator.runtimeAnimatorController;

        if (animatorInternal != null)
        {
            AnimatorControllerLayer[]            layers   = animatorInternal.layers;
            UnityEditor.Animations.AnimatorState newState = layers[layerId].stateMachine.AddState(sateName);
            newState.motion = Motion;
            return(newState);
        }
        return(null);
    }
コード例 #13
0
 private void ClearStateMachine()
 {
     if (avatarPreview != null && avatarPreview.Animator != null)
     {
         UnityEditor.Animations.AnimatorController.SetAnimatorController(avatarPreview.Animator, null);
     }
     Object.DestroyImmediate(this.controller);
     Object.DestroyImmediate(this.stateMachine);
     Object.DestroyImmediate(this.state);
     stateMachine = null;
     controller   = null;
     state        = null;
 }
コード例 #14
0
    void DrawLayerPanel()
    {
        GUILayout.BeginVertical(GUILayout.Width(200));

        if (targetController != null)
        {
            int layerCount = 0;
            GUILayout.Label(layerCount + " layer(s) in selected controller");

            if (Event.current.type == EventType.Layout)
            {
                layers = new UnityEditor.Animations.AnimatorControllerLayer[layerCount];
                for (int layer = 0; layer < layerCount; layer++)
                {
                    //	layers[layer] = targetController.GetLayer(layer);
                }
            }

            GUILayout.BeginVertical("Box");
            layerPanelScrollPos = GUILayout.BeginScrollView(layerPanelScrollPos);

            string[] layerNames = new string[layerCount];

            for (int layer = 0; layer < layerCount; layer++)
            {
                layerNames[layer] = "[" + layer.ToString() + "]" + layers[layer].name;
            }

            selectedLayer = GUILayout.SelectionGrid(selectedLayer, layerNames, 1);

            if (selectedLayer >= 0 && selectedLayer < layerCount)
            {
                targetStateMachine = layers[selectedLayer].stateMachine;
            }
            else
            {
                targetStateMachine = null;
                targetState        = null;
                targetEvent        = null;
            }

            GUILayout.EndScrollView();
            GUILayout.EndVertical();
        }
        else
        {
            GUILayout.Label("No layer available.");
        }

        GUILayout.EndVertical();
    }
コード例 #15
0
    public static AnimatorState GetState(Animator animator, string stateName, int layer = 0)
    {
        ChildAnimatorState[] childStates = ((UnityEditor.Animations.AnimatorController)animator.runtimeAnimatorController).layers[layer].stateMachine.states;

        for (int i = 0; i < childStates.Length; i++)
        {
            if (childStates[i].state.name == stateName)
            {
                UnityEditor.Animations.AnimatorState tes = childStates[i].state;
                return(childStates[i].state);
            }
        }
        return(null);
    }
コード例 #16
0
 static UnityEditor.Animations.AnimatorController BuildAnimationController(List <AnimationClip> clips, string name)
 {
     System.IO.Directory.CreateDirectory(animationControllerPath);
     UnityEditor.Animations.AnimatorController      animatorController = UnityEditor.Animations.AnimatorController.CreateAnimatorControllerAtPath(animationControllerPath + "/" + name + ".controller");
     UnityEditor.Animations.AnimatorControllerLayer layer = animatorController.layers[0];
     UnityEditor.Animations.AnimatorStateMachine    sm    = layer.stateMachine;
     foreach (AnimationClip newClip in clips)
     {
         UnityEditor.Animations.AnimatorState state = sm.AddState(newClip.name);
         state.motion = newClip;
     }
     AssetDatabase.SaveAssets();
     return(animatorController);
 }
コード例 #17
0
ファイル: AnimatorCheckEditor.cs プロジェクト: zwong91/Titan
    private void traverseCheckStateDict(int depth, string path, UnityEditor.Animations.AnimatorStateMachine stateMachine)
    {
        foreach (var sta in stateMachine.stateMachines)
        {
            //Debug.Log("Depth=" + depth + " stateMachines " + sta.stateMachine);
            string newPath = path;
            newPath = newPath + sta.stateMachine.name + "->";
            traverseCheckStateDict(depth + 1, newPath, sta.stateMachine);
        }

        foreach (UnityEditor.Animations.ChildAnimatorState sta in stateMachine.states)
        {
            if (sta.state != null)
            {
                if (!stateDict.ContainsKey(sta.state.name))
                {
                    Debug.LogError("攻击层和上半身攻击层配置应该是一样的,可是" + path + "动作" + sta.state.name + "只有上半身攻击层有,或者在同层的不同子状态机里有同名,请检查");
                    continue;
                }

                UnityEditor.Animations.AnimatorState attackState = stateDict[sta.state.name];

                if (attackState.transitions.Length != sta.state.transitions.Length)
                {
                    Debug.LogError("攻击层和上半身攻击层配置应该是一样的,可是" + path + "动作" + sta.state.name + "在两层里面的动作切换数目不一致,请检查");
                    continue;
                }

                foreach (var upTransform in sta.state.transitions)
                {
                    bool found = false;
                    foreach (var attackTransform in attackState.transitions)
                    {
                        if (compareTranslation(upTransform, attackTransform))
                        {
                            found = true;
                            break;
                        }
                    }

                    if (!found)
                    {
                        Debug.LogError("攻击层和上半身攻击层配置应该是一样的,可是攻击层" + sta.state.name + "到" + upTransform.destinationState.name + "在上半身攻击层没找到完全匹配的过渡,请检查");
                    }
                }

                stateDict.Remove(sta.state.name);
            }
        }
    }
コード例 #18
0
    void Reset()
    {
        displayEvents = null;

        targetController   = null;
        targetStateMachine = null;
        targetState        = null;
        targetEvent        = null;

        selectedLayer = 0;
        selectedState = 0;
        selectedEvent = 0;

        MecanimEventEditorPopup.Destroy();
    }
コード例 #19
0
    static AnimatorController BuildAnimationController(List <AnimationClip> clips, string name)
    {
        AnimatorController      animatorController = AnimatorController.CreateAnimatorControllerAtPath(AnimationControllerPath + "/" + name + ".controller");
        AnimatorControllerLayer layer = animatorController.layers[0];
        AnimatorStateMachine    sm    = layer.stateMachine;

        foreach (AnimationClip newClip in clips)
        {
            UnityEditor.Animations.AnimatorState state = sm.AddState(newClip.name);
            state.motion = newClip;
            AnimatorStateTransition trans = sm.AddAnyStateTransition(state);
        }
        AssetDatabase.SaveAssets();
        return(animatorController);
    }
コード例 #20
0
        public static UnityEditor.Animations.AnimatorState RemoveStateWith(this UnityEditor.Animations.AnimatorController controller, int nameHash, int layerIndex = 0)
        {
            UnityEditor.Animations.AnimatorState state = controller.GetStateBy(nameHash, layerIndex);

            if (state != null)
            {
                controller.layers [layerIndex].stateMachine.RemoveState(state);

                return(state);
            }



            return(null);
        }
コード例 #21
0
    private static void AddStateTransition(string path, UnityEditor.Animations.AnimatorControllerLayer layer, string motionName, Vector3 pos)
    {
        UnityEditor.Animations.AnimatorStateMachine sm = layer.stateMachine;
        Motion motion = AssetDatabase.LoadAssetAtPath(path, typeof(Motion)) as Motion;          //根据动画文件读取它的Motion对象

        UnityEditor.Animations.AnimatorState state = sm.AddState(motionName, pos);              //motion.name

        state.motion = motion;                                                                  //取出动画名子 添加到state里面
        UnityEditor.Animations.AnimatorStateTransition trans = sm.AddAnyStateTransition(state); //把state添加在layer里面

        trans.hasExitTime = false;                                                              //把默认的时间条件删除 //false
        //trans.exitTime = 1f; //0.9f

        trans.duration            = 0f;   //默认过渡时间 // 0.1f
        trans.canTransitionToSelf = true; //默认true
    }
コード例 #22
0
    public void setLevel(int level, RuntimeAnimatorController animatorController, RuntimeAnimatorController animatorControllerClone)
    {
        LevelGK levelGK = getLevelGK(level);

        if (levelGK == null)
        {
            return;
        }

        _flyDistance = levelGK._flyDistance;
        _moveSpeed   = levelGK._moveSpeed;
        _responsive  = levelGK._responsive;



        _animatorController      = animatorController;
        _animatorControllerClone = animatorControllerClone;


        UnityEditor.Animations.AnimatorController   ac = _animatorController as UnityEditor.Animations.AnimatorController;
        UnityEditor.Animations.AnimatorStateMachine sm = ac.layers[0].stateMachine;
        for (int i = 0; i < sm.states.Length; i++)
        {
            UnityEditor.Animations.AnimatorState state = sm.states[i].state;
            //			Debug.Log(string.Format("State: {0}", state.uniqueName));
            if (state.name.Equals("save") || state.name.Equals("save center"))
            {
                state.speed = _responsive;
            }
            else if (state.name.Equals("move left") || state.name.Equals("move right"))
            {
                state.speed = _moveSpeed;
            }
        }

        ac = _animatorControllerClone as UnityEditor.Animations.AnimatorController;
        sm = ac.layers[0].stateMachine;
        for (int i = 0; i < sm.states.Length; i++)
        {
            UnityEditor.Animations.AnimatorState state = sm.states[i].state;
            //			Debug.Log(string.Format("State: {0}", state.uniqueName));
            if (state.name.Equals("save") || state.name.Equals("save center"))
            {
                state.speed = _responsive;
            }
        }
    }
コード例 #23
0
    public static float GetStateLength(Animator animator, string stateName)
    {
        UnityEditor.Animations.AnimatorState animState = AnimatorUtility.GetState(animator, stateName, 0);
        if (animState == null)
        {
            return(0f);
        }

        if (animState.motion == null)
        {
            return(0f);
        }

        var clip = (AnimationClip)animState.motion;

        return(clip.length);
    }
コード例 #24
0
        public static int GetLayerIndex(AnimatorController aniController, AnimatorState state)
        {
            if (!animatorControllerStateLayerInx.ContainsKey(aniController))
            {
                processAnimatorController(aniController);
            }

            Dictionary <AnimatorState, int> dict;

            dict = animatorControllerStateLayerInx [aniController];

            if (dict != null && dict.ContainsKey(state))
            {
                return(dict [state]);
            }

            return(-1);
        }
コード例 #25
0
    private static UnityEditor.Animations.AnimatorState CreateState(UnityEditor.Animations.AnimatorStateMachine machine, string name, AnimationClip anim, Vector3 pos)
    {
        foreach (var item in machine.states)
        {
            if (item.state.name == name)
            {
                return(item.state);
            }
        }
        UnityEditor.Animations.AnimatorState state = machine.AddState(name);
        state.motion = anim;
        //state.SetAnimationClip(anim);
        var state1 = ArrayUtility.Find <UnityEditor.Animations.ChildAnimatorState>(machine.states, x => x.state == state);

        state1.position = pos;
        //state.position = pos;
        return(state);
    }
コード例 #26
0
    void DrawStatePanel()
    {
        GUILayout.BeginVertical(GUILayout.Width(200));

        if (targetStateMachine != null)
        {
            List <UnityEditor.Animations.AnimatorState> availableStates = GetStatesRecursive(targetStateMachine);
            List <string> stateNames = new List <string>();

            //foreach (UnityEditor.Animations.AnimatorState s in availableStates) {
            //stateNames.Add(s.uniqueName);
            //}

            GUILayout.Label(availableStates.Count + " state(s) in selected layer.");

            GUILayout.BeginVertical("Box");
            statePanelScrollPos = GUILayout.BeginScrollView(statePanelScrollPos);

            selectedState = GUILayout.SelectionGrid(selectedState, stateNames.ToArray(), 1);

            if (selectedState >= 0 && selectedState < availableStates.Count)
            {
                targetState = availableStates[selectedState];
            }
            else
            {
                targetState = null;
                targetEvent = null;
            }

            GUILayout.EndScrollView();
            GUILayout.EndVertical();
        }
        else
        {
            GUILayout.Label("No state machine available.");
        }

        GUILayout.EndVertical();
    }
コード例 #27
0
    public static List <string> GetAllStateNamesWithController(RuntimeAnimatorController controller)
    {
        var availableStateNames = new List <string>();

        if (controller == null)
        {
            return(availableStateNames);
        }

        if (controller is UnityEditor.Animations.AnimatorController)
        {
            var ac = controller as UnityEditor.Animations.AnimatorController;
            for (int j = 0; j < ac.layers.Length; j++)
            {
                var sm = ac.layers[j].stateMachine;
                for (int i = 0; i < sm.states.Length; i++)
                {
                    UnityEditor.Animations.AnimatorState state = sm.states[i].state;
                    var stateName = state.name;
                    availableStateNames.Add(stateName);
                }
            }
        }
        else if (controller is UnityEngine.AnimatorOverrideController)
        {
            var aoc = controller as UnityEngine.AnimatorOverrideController;
            aoc.animationClips.ToList().ForEach(animationClip => availableStateNames.Add(animationClip.name));
        }
        else if (controller != null)
        {
            controller.animationClips.ToList().ForEach(animationClip => availableStateNames.Add(animationClip.name));
        }
        else
        {
            Debug.LogError("AnimatorController Type not supported");
        }

        return(availableStateNames);
    }
コード例 #28
0
        public void SetData(UnityEditor.Animations.AnimatorState pState)
        {
            name     = pState.name;
            hashName = pState.nameHash;
            speed    = pState.speed;

            AnimationClip clip = pState.motion as AnimationClip;

            motionName = clip != null ? clip.name: "";

            transtionList.Clear();
            AnimatorStateTransition[] transs = pState.transitions;
            for (int k = 0; k < transs.Length; k++)
            {
                AnimatorStateTransition     transdata  = transs[k];
                AssetTransitions.Transtions ttranstion = new AssetTransitions.Transtions()
                {
                    ownerMachineIndex = machineIndex
                };
                ttranstion.CopyData(transdata);
                transtionList.Add(ttranstion);
            }
        }
コード例 #29
0
    public static List <string> GetAllStateNamesWithControllerInLayer(UnityEditor.Animations.AnimatorController controller, int Layer)
    {
        var availableStateNames = new List <string>();

        if (controller == null)
        {
            return(availableStateNames);
        }

        var ac = controller as UnityEditor.Animations.AnimatorController;

        if (Layer >= 0 && Layer < ac.layers.Length)
        {
            var sm = ac.layers[Layer].stateMachine;
            for (int i = 0; i < sm.states.Length; i++)
            {
                UnityEditor.Animations.AnimatorState state = sm.states[i].state;
                var stateName = state.name;
                availableStateNames.Add(stateName);
            }
        }

        return(availableStateNames);
    }
コード例 #30
0
    void CheckResources()
    {
        ActiveTextures.Clear();
        ActiveMaterials.Clear();
        ActiveMeshDetails.Clear();

        Renderer[] renderers = FindObjects <Renderer>();

        //Debug.Log("Total renderers "+renderers.Length);
        foreach (Renderer renderer in renderers)
        {
            //Debug.Log("Renderer is "+renderer.name);
            foreach (Material material in renderer.sharedMaterials)
            {
                MaterialDetails tMaterialDetails = FindMaterialDetails(material);
                if (tMaterialDetails == null)
                {
                    tMaterialDetails          = new MaterialDetails();
                    tMaterialDetails.material = material;
                    ActiveMaterials.Add(tMaterialDetails);
                }
                tMaterialDetails.FoundInRenderers.Add(renderer);
            }

            if (renderer is SpriteRenderer)
            {
                SpriteRenderer tSpriteRenderer = (SpriteRenderer)renderer;

                if (tSpriteRenderer.sprite != null)
                {
                    var tSpriteTextureDetail = GetTextureDetail(tSpriteRenderer.sprite.texture, renderer);
                    if (!ActiveTextures.Contains(tSpriteTextureDetail))
                    {
                        ActiveTextures.Add(tSpriteTextureDetail);
                    }
                }
            }
        }

        if (IncludeGuiElements)
        {
            Graphic[] graphics = FindObjects <Graphic>();

            foreach (Graphic graphic in graphics)
            {
                if (graphic.mainTexture)
                {
                    var tSpriteTextureDetail = GetTextureDetail(graphic.mainTexture, graphic);
                    if (!ActiveTextures.Contains(tSpriteTextureDetail))
                    {
                        ActiveTextures.Add(tSpriteTextureDetail);
                    }
                }

                if (graphic.materialForRendering)
                {
                    MaterialDetails tMaterialDetails = FindMaterialDetails(graphic.materialForRendering);
                    if (tMaterialDetails == null)
                    {
                        tMaterialDetails          = new MaterialDetails();
                        tMaterialDetails.material = graphic.materialForRendering;
                        ActiveMaterials.Add(tMaterialDetails);
                    }
                    tMaterialDetails.FoundInGraphics.Add(graphic);
                }
            }
        }

        foreach (MaterialDetails tMaterialDetails in ActiveMaterials)
        {
            Material tMaterial = tMaterialDetails.material;
            if (tMaterial != null)
            {
                var dependencies = EditorUtility.CollectDependencies(new UnityEngine.Object[] { tMaterial });
                foreach (Object obj in dependencies)
                {
                    if (obj is Texture)
                    {
                        Texture tTexture       = obj as Texture;
                        var     tTextureDetail = GetTextureDetail(tTexture, tMaterial, tMaterialDetails);
                        ActiveTextures.Add(tTextureDetail);
                    }
                }

                //if the texture was downloaded, it won't be included in the editor dependencies
                if (tMaterial.mainTexture != null && !dependencies.Contains(tMaterial.mainTexture))
                {
                    var tTextureDetail = GetTextureDetail(tMaterial.mainTexture, tMaterial, tMaterialDetails);
                    ActiveTextures.Add(tTextureDetail);
                }
            }
        }


        MeshFilter[] meshFilters = FindObjects <MeshFilter>();

        foreach (MeshFilter tMeshFilter in meshFilters)
        {
            Mesh tMesh = tMeshFilter.sharedMesh;
            if (tMesh != null)
            {
                MeshDetails tMeshDetails = FindMeshDetails(tMesh);
                if (tMeshDetails == null)
                {
                    tMeshDetails      = new MeshDetails();
                    tMeshDetails.mesh = tMesh;
                    ActiveMeshDetails.Add(tMeshDetails);
                }
                tMeshDetails.FoundInMeshFilters.Add(tMeshFilter);
            }
        }

        SkinnedMeshRenderer[] skinnedMeshRenderers = FindObjects <SkinnedMeshRenderer>();

        foreach (SkinnedMeshRenderer tSkinnedMeshRenderer in skinnedMeshRenderers)
        {
            Mesh tMesh = tSkinnedMeshRenderer.sharedMesh;
            if (tMesh != null)
            {
                MeshDetails tMeshDetails = FindMeshDetails(tMesh);
                if (tMeshDetails == null)
                {
                    tMeshDetails      = new MeshDetails();
                    tMeshDetails.mesh = tMesh;
                    ActiveMeshDetails.Add(tMeshDetails);
                }
                tMeshDetails.FoundInSkinnedMeshRenderer.Add(tSkinnedMeshRenderer);
            }
        }

        if (IncludeSpriteAnimations)
        {
            Animator[] animators = FindObjects <Animator>();
            foreach (Animator anim in animators)
            {
                                #if UNITY_4_6 || UNITY_4_5 || UNITY_4_4 || UNITY_4_3
                UnityEditorInternal.AnimatorController ac = anim.runtimeAnimatorController as UnityEditorInternal.AnimatorController;
                                #elif UNITY_5
                UnityEditor.Animations.AnimatorController ac = anim.runtimeAnimatorController as UnityEditor.Animations.AnimatorController;
                                #endif

                //Skip animators without layers, this can happen if they don't have an animator controller.
                if (!ac || ac.layers == null || ac.layers.Length == 0)
                {
                    continue;
                }

                for (int x = 0; x < anim.layerCount; x++)
                {
                                        #if UNITY_4_6 || UNITY_4_5 || UNITY_4_4 || UNITY_4_3
                    UnityEditorInternal.StateMachine sm = ac.GetLayer(x).stateMachine;
                    int cnt = sm.stateCount;
                                        #elif UNITY_5
                    UnityEditor.Animations.AnimatorStateMachine sm = ac.layers[x].stateMachine;
                    int cnt = sm.states.Length;
                                        #endif

                    for (int i = 0; i < cnt; i++)
                    {
                                                #if UNITY_4_6 || UNITY_4_5 || UNITY_4_4 || UNITY_4_3
                        UnityEditorInternal.State state = sm.GetState(i);
                        Motion m = state.GetMotion();
                                                #elif UNITY_5
                        UnityEditor.Animations.AnimatorState state = sm.states[i].state;
                        Motion m = state.motion;
                                                #endif
                        if (m != null)
                        {
                            AnimationClip clip = m as AnimationClip;

                            EditorCurveBinding[] ecbs = AnimationUtility.GetObjectReferenceCurveBindings(clip);

                            foreach (EditorCurveBinding ecb in ecbs)
                            {
                                if (ecb.propertyName == "m_Sprite")
                                {
                                    foreach (ObjectReferenceKeyframe keyframe in AnimationUtility.GetObjectReferenceCurve(clip, ecb))
                                    {
                                        Sprite tSprite = keyframe.value as Sprite;

                                        if (tSprite != null)
                                        {
                                            var tTextureDetail = GetTextureDetail(tSprite.texture, anim);
                                            if (!ActiveTextures.Contains(tTextureDetail))
                                            {
                                                ActiveTextures.Add(tTextureDetail);
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }

        if (IncludeScriptReferences)
        {
            MonoBehaviour[] scripts = FindObjects <MonoBehaviour>();
            foreach (MonoBehaviour script in scripts)
            {
                BindingFlags flags  = BindingFlags.Public | BindingFlags.Instance;                // only public non-static fields are bound to by Unity.
                FieldInfo[]  fields = script.GetType().GetFields(flags);

                foreach (FieldInfo field in fields)
                {
                    System.Type fieldType = field.FieldType;
                    if (fieldType == typeof(Sprite))
                    {
                        Sprite tSprite = field.GetValue(script) as Sprite;
                        if (tSprite != null)
                        {
                            var tSpriteTextureDetail = GetTextureDetail(tSprite.texture, script);
                            if (!ActiveTextures.Contains(tSpriteTextureDetail))
                            {
                                ActiveTextures.Add(tSpriteTextureDetail);
                            }
                        }
                    }
                }
            }
        }

        TotalTextureMemory = 0;
        foreach (TextureDetails tTextureDetails in ActiveTextures)
        {
            TotalTextureMemory += tTextureDetails.memSizeKB;
        }

        TotalMeshVertices = 0;
        foreach (MeshDetails tMeshDetails in ActiveMeshDetails)
        {
            TotalMeshVertices += tMeshDetails.mesh.vertexCount;
        }

        // Sort by size, descending
        ActiveTextures.Sort(delegate(TextureDetails details1, TextureDetails details2) { return(details2.memSizeKB - details1.memSizeKB); });
        ActiveMeshDetails.Sort(delegate(MeshDetails details1, MeshDetails details2) { return(details2.mesh.vertexCount - details1.mesh.vertexCount); });

        collectedInPlayingMode = Application.isPlaying;
    }
コード例 #31
0
    void CheckResources()
    {
        ActiveTextures.Clear();
        ActiveMaterials.Clear();
        ActiveMeshDetails.Clear();
        MissingObjects.Clear();
        thingsMissing = false;

        Renderer[] renderers = FindObjects <Renderer>();

        MaterialDetails skyMat = new MaterialDetails();

        skyMat.material = RenderSettings.skybox;
        skyMat.isSky    = true;
        ActiveMaterials.Add(skyMat);

        //Debug.Log("Total renderers "+renderers.Length);
        foreach (Renderer renderer in renderers)
        {
            //Debug.Log("Renderer is "+renderer.name);
            foreach (Material material in renderer.sharedMaterials)
            {
                MaterialDetails tMaterialDetails = FindMaterialDetails(material);
                if (tMaterialDetails == null)
                {
                    tMaterialDetails          = new MaterialDetails();
                    tMaterialDetails.material = material;
                    ActiveMaterials.Add(tMaterialDetails);
                }
                tMaterialDetails.FoundInRenderers.Add(renderer);
            }

            if (renderer is SpriteRenderer)
            {
                SpriteRenderer tSpriteRenderer = (SpriteRenderer)renderer;

                if (tSpriteRenderer.sprite != null)
                {
                    var tSpriteTextureDetail = GetTextureDetail(tSpriteRenderer.sprite.texture, renderer);
                    if (!ActiveTextures.Contains(tSpriteTextureDetail))
                    {
                        ActiveTextures.Add(tSpriteTextureDetail);
                    }
                }
                else if (tSpriteRenderer.sprite == null)
                {
                    MissingGraphic tMissing = new MissingGraphic();
                    tMissing.Object = tSpriteRenderer.transform;
                    tMissing.type   = "sprite";
                    tMissing.name   = tSpriteRenderer.transform.name;
                    MissingObjects.Add(tMissing);
                    thingsMissing = true;
                }
            }
        }

        if (IncludeLightmapTextures)
        {
            LightmapData[] lightmapTextures = LightmapSettings.lightmaps;

            // Unity lightmaps
            foreach (LightmapData lightmapData in lightmapTextures)
            {
                if (lightmapData.lightmapColor != null)
                {
                    var textureDetail = GetTextureDetail(lightmapData.lightmapColor);

                    if (!ActiveTextures.Contains(textureDetail))
                    {
                        ActiveTextures.Add(textureDetail);
                    }
                }

                if (lightmapData.lightmapDir != null)
                {
                    var textureDetail = GetTextureDetail(lightmapData.lightmapColor);

                    if (!ActiveTextures.Contains(textureDetail))
                    {
                        ActiveTextures.Add(textureDetail);
                    }
                }

                if (lightmapData.shadowMask != null)
                {
                    var textureDetail = GetTextureDetail(lightmapData.shadowMask);

                    if (!ActiveTextures.Contains(textureDetail))
                    {
                        ActiveTextures.Add(textureDetail);
                    }
                }
            }
        }

        if (IncludeGuiElements)
        {
            Graphic[] graphics = FindObjects <Graphic>();

            foreach (Graphic graphic in graphics)
            {
                if (graphic.mainTexture)
                {
                    var tSpriteTextureDetail = GetTextureDetail(graphic.mainTexture, graphic);
                    if (!ActiveTextures.Contains(tSpriteTextureDetail))
                    {
                        ActiveTextures.Add(tSpriteTextureDetail);
                    }
                }

                if (graphic.materialForRendering)
                {
                    MaterialDetails tMaterialDetails = FindMaterialDetails(graphic.materialForRendering);
                    if (tMaterialDetails == null)
                    {
                        tMaterialDetails          = new MaterialDetails();
                        tMaterialDetails.material = graphic.materialForRendering;
                        tMaterialDetails.isgui    = true;
                        ActiveMaterials.Add(tMaterialDetails);
                    }
                    tMaterialDetails.FoundInGraphics.Add(graphic);
                }
            }

            Button[] buttons = FindObjects <Button>();
            foreach (Button button in buttons)
            {
                CheckButtonSpriteState(button, button.spriteState.disabledSprite);
                CheckButtonSpriteState(button, button.spriteState.highlightedSprite);
                CheckButtonSpriteState(button, button.spriteState.pressedSprite);
            }
        }

        foreach (MaterialDetails tMaterialDetails in ActiveMaterials)
        {
            Material tMaterial = tMaterialDetails.material;
            if (tMaterial != null)
            {
                var dependencies = EditorUtility.CollectDependencies(new UnityEngine.Object[] { tMaterial });
                foreach (Object obj in dependencies)
                {
                    if (obj is Texture)
                    {
                        Texture tTexture       = obj as Texture;
                        var     tTextureDetail = GetTextureDetail(tTexture, tMaterial, tMaterialDetails);
                        tTextureDetail.isSky    = tMaterialDetails.isSky;
                        tTextureDetail.instance = tMaterialDetails.instance;
                        tTextureDetail.isgui    = tMaterialDetails.isgui;
                        ActiveTextures.Add(tTextureDetail);
                    }
                }

                //if the texture was downloaded, it won't be included in the editor dependencies
                if (tMaterial.HasProperty("_MainTex"))
                {
                    if (tMaterial.mainTexture != null && !dependencies.Contains(tMaterial.mainTexture))
                    {
                        var tTextureDetail = GetTextureDetail(tMaterial.mainTexture, tMaterial, tMaterialDetails);
                        ActiveTextures.Add(tTextureDetail);
                    }
                }
            }
        }


        MeshFilter[] meshFilters = FindObjects <MeshFilter>();

        foreach (MeshFilter tMeshFilter in meshFilters)
        {
            Mesh tMesh = tMeshFilter.sharedMesh;
            if (tMesh != null)
            {
                MeshDetails tMeshDetails = FindMeshDetails(tMesh);
                if (tMeshDetails == null)
                {
                    tMeshDetails      = new MeshDetails();
                    tMeshDetails.mesh = tMesh;
                    ActiveMeshDetails.Add(tMeshDetails);
                }
                tMeshDetails.FoundInMeshFilters.Add(tMeshFilter);

                if (GameObjectUtility.AreStaticEditorFlagsSet(tMeshFilter.gameObject, StaticEditorFlags.BatchingStatic))
                {
                    tMeshDetails.StaticBatchingEnabled.Add(tMeshFilter.gameObject);
                }
            }
            else if (tMesh == null && tMeshFilter.transform.GetComponent("TextContainer") == null)
            {
                MissingGraphic tMissing = new MissingGraphic();
                tMissing.Object = tMeshFilter.transform;
                tMissing.type   = "mesh";
                tMissing.name   = tMeshFilter.transform.name;
                MissingObjects.Add(tMissing);
                thingsMissing = true;
            }

            var meshRenderrer = tMeshFilter.transform.GetComponent <MeshRenderer>();

            if (meshRenderrer == null || meshRenderrer.sharedMaterial == null)
            {
                MissingGraphic tMissing = new MissingGraphic();
                tMissing.Object = tMeshFilter.transform;
                tMissing.type   = "material";
                tMissing.name   = tMeshFilter.transform.name;
                MissingObjects.Add(tMissing);
                thingsMissing = true;
            }
        }

        SkinnedMeshRenderer[] skinnedMeshRenderers = FindObjects <SkinnedMeshRenderer>();

        foreach (SkinnedMeshRenderer tSkinnedMeshRenderer in skinnedMeshRenderers)
        {
            Mesh tMesh = tSkinnedMeshRenderer.sharedMesh;
            if (tMesh != null)
            {
                MeshDetails tMeshDetails = FindMeshDetails(tMesh);
                if (tMeshDetails == null)
                {
                    tMeshDetails      = new MeshDetails();
                    tMeshDetails.mesh = tMesh;
                    ActiveMeshDetails.Add(tMeshDetails);
                }
                tMeshDetails.FoundInSkinnedMeshRenderer.Add(tSkinnedMeshRenderer);
            }
            else if (tMesh == null)
            {
                MissingGraphic tMissing = new MissingGraphic();
                tMissing.Object = tSkinnedMeshRenderer.transform;
                tMissing.type   = "mesh";
                tMissing.name   = tSkinnedMeshRenderer.transform.name;
                MissingObjects.Add(tMissing);
                thingsMissing = true;
            }
            if (tSkinnedMeshRenderer.sharedMaterial == null)
            {
                MissingGraphic tMissing = new MissingGraphic();
                tMissing.Object = tSkinnedMeshRenderer.transform;
                tMissing.type   = "material";
                tMissing.name   = tSkinnedMeshRenderer.transform.name;
                MissingObjects.Add(tMissing);
                thingsMissing = true;
            }
        }

        if (IncludeSpriteAnimations)
        {
            Animator[] animators = FindObjects <Animator>();
            foreach (Animator anim in animators)
            {
                                #if UNITY_4_6 || UNITY_4_5 || UNITY_4_4 || UNITY_4_3
                UnityEditorInternal.AnimatorController ac = anim.runtimeAnimatorController as UnityEditorInternal.AnimatorController;
                                #elif UNITY_5 || UNITY_5_3_OR_NEWER
                UnityEditor.Animations.AnimatorController ac = anim.runtimeAnimatorController as UnityEditor.Animations.AnimatorController;
                                #endif

                //Skip animators without layers, this can happen if they don't have an animator controller.
                if (!ac || ac.layers == null || ac.layers.Length == 0)
                {
                    continue;
                }

                for (int x = 0; x < anim.layerCount; x++)
                {
                    UnityEditor.Animations.AnimatorStateMachine sm = ac.layers[x].stateMachine;
                    int cnt = sm.states.Length;

                    for (int i = 0; i < cnt; i++)
                    {
                        UnityEditor.Animations.AnimatorState state = sm.states[i].state;
                        Motion m = state.motion;
                        if (m != null)
                        {
                            AnimationClip clip = m as AnimationClip;

                            if (clip != null)
                            {
                                EditorCurveBinding[] ecbs = AnimationUtility.GetObjectReferenceCurveBindings(clip);

                                foreach (EditorCurveBinding ecb in ecbs)
                                {
                                    if (ecb.propertyName == "m_Sprite")
                                    {
                                        foreach (ObjectReferenceKeyframe keyframe in AnimationUtility.GetObjectReferenceCurve(clip, ecb))
                                        {
                                            Sprite tSprite = keyframe.value as Sprite;

                                            if (tSprite != null)
                                            {
                                                var tTextureDetail = GetTextureDetail(tSprite.texture, anim);
                                                if (!ActiveTextures.Contains(tTextureDetail))
                                                {
                                                    ActiveTextures.Add(tTextureDetail);
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }

        if (IncludeScriptReferences)
        {
            MonoBehaviour[] scripts = FindObjects <MonoBehaviour>();
            foreach (MonoBehaviour script in scripts)
            {
                BindingFlags flags  = BindingFlags.Public | BindingFlags.Instance;                // only public non-static fields are bound to by Unity.
                FieldInfo[]  fields = script.GetType().GetFields(flags);

                foreach (FieldInfo field in fields)
                {
                    System.Type fieldType = field.FieldType;
                    if (fieldType == typeof(Sprite))
                    {
                        Sprite tSprite = field.GetValue(script) as Sprite;
                        if (tSprite != null)
                        {
                            var tSpriteTextureDetail = GetTextureDetail(tSprite.texture, script);
                            if (!ActiveTextures.Contains(tSpriteTextureDetail))
                            {
                                ActiveTextures.Add(tSpriteTextureDetail);
                            }
                        }
                    }
                    if (fieldType == typeof(Mesh))
                    {
                        Mesh tMesh = field.GetValue(script) as Mesh;
                        if (tMesh != null)
                        {
                            MeshDetails tMeshDetails = FindMeshDetails(tMesh);
                            if (tMeshDetails == null)
                            {
                                tMeshDetails          = new MeshDetails();
                                tMeshDetails.mesh     = tMesh;
                                tMeshDetails.instance = true;
                                ActiveMeshDetails.Add(tMeshDetails);
                            }
                        }
                    }
                    if (fieldType == typeof(Material))
                    {
                        Material tMaterial = field.GetValue(script) as Material;
                        if (tMaterial != null)
                        {
                            MaterialDetails tMatDetails = FindMaterialDetails(tMaterial);
                            if (tMatDetails == null)
                            {
                                tMatDetails          = new MaterialDetails();
                                tMatDetails.instance = true;
                                tMatDetails.material = tMaterial;
                                if (!ActiveMaterials.Contains(tMatDetails))
                                {
                                    ActiveMaterials.Add(tMatDetails);
                                }
                            }
                            if (tMaterial.mainTexture)
                            {
                                var tSpriteTextureDetail = GetTextureDetail(tMaterial.mainTexture);
                                if (!ActiveTextures.Contains(tSpriteTextureDetail))
                                {
                                    ActiveTextures.Add(tSpriteTextureDetail);
                                }
                            }
                            var dependencies = EditorUtility.CollectDependencies(new UnityEngine.Object[] { tMaterial });
                            foreach (Object obj in dependencies)
                            {
                                if (obj is Texture)
                                {
                                    Texture tTexture       = obj as Texture;
                                    var     tTextureDetail = GetTextureDetail(tTexture, tMaterial, tMatDetails);
                                    if (!ActiveTextures.Contains(tTextureDetail))
                                    {
                                        ActiveTextures.Add(tTextureDetail);
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }

        TotalTextureMemory = 0;
        foreach (TextureDetails tTextureDetails in ActiveTextures)
        {
            TotalTextureMemory += tTextureDetails.memSizeKB;
        }

        TotalMeshVertices = 0;
        foreach (MeshDetails tMeshDetails in ActiveMeshDetails)
        {
            TotalMeshVertices += tMeshDetails.mesh.vertexCount;
        }

        // Sort by size, descending
        ActiveTextures.Sort(delegate(TextureDetails details1, TextureDetails details2) { return(details2.memSizeKB - details1.memSizeKB); });
        ActiveTextures = ActiveTextures.Distinct().ToList();
        ActiveMeshDetails.Sort(delegate(MeshDetails details1, MeshDetails details2) { return(details2.mesh.vertexCount - details1.mesh.vertexCount); });

        collectedInPlayingMode = Application.isPlaying;

        // Sort by render queue
        ActiveMaterials.Sort(MaterialSorter);
    }
コード例 #32
0
ファイル: MecanimUtility.cs プロジェクト: osmanzeki/bmachine
        public static int GetLayerIndex(AnimatorController aniController, AnimatorState state)
        {
            if (!animatorControllerStateLayerInx.ContainsKey (aniController)) {
                                processAnimatorController (aniController);

                        }

                            Dictionary<AnimatorState,int> dict;

                                dict = animatorControllerStateLayerInx [aniController];

                                if (dict != null && dict.ContainsKey (state)) {
                                        return dict [state];
                                }

                        return -1;
        }
コード例 #33
0
        //
        // Methods
        //
        /// <summary>
        /// Handles the onGUI event.
        /// </summary>
        /// <param name="property">Property.</param>
        /// <param name="node">Node.</param>
        /// <param name="guiContent">GUI content.</param>
        public override void OnGUI(SerializedNodeProperty property, ActionNode node, GUIContent guiContent)
        {
            //if (animatorSerialized == null || aniController == null) {
                        if(aniController == null) {

                                //!!! Serialization never serialized Animator cos its initialized in Reset after
            //								NodePropertyIterator iter= property.serializedNode.GetIterator();
            //								iter.Find(attribute.animatorFieldName);
            //								 animatorSerialized=iter.current;
                                //				//								if(animatorSerialized==null || animatorSerialized.value==null){
                                //										Debug.LogError("AnimatorStateNodePropertyDrawer> No Animator component set on node parent GameObject");
                                //									return;
                                //								}

                                //runtimeContoller =( (Animator)animatorSerialized.value).runtimeAnimatorController;
                                Animator animator = node.GetType ().GetField (attribute.animatorFieldName).GetValue (node) as Animator;

                                RuntimeAnimatorController runtimeContoller;

                                runtimeContoller = animator.runtimeAnimatorController;

                                if (runtimeContoller is AnimatorOverrideController)
                                        aniController = ((AnimatorOverrideController)runtimeContoller).runtimeAnimatorController as UnityEditor.Animations.AnimatorController;
                                else
                                        aniController = runtimeContoller as UnityEditor.Animations.AnimatorController;

                        }

                        animatorStateDisplayOptions = MecanimUtility.GetDisplayOptions (aniController);
                        animatorStateValues = MecanimUtility.GetAnimatorStates (aniController);

                        if(property.value!=null){

                            if(animatorStateValues.Length>0){
                                    animatorStateSelectedPrev=animatorStateSelected=animatorStateValues.FirstOrDefault((itm)=>itm.nameHash==((ws.winx.unity.AnimatorState)property.value).nameHash);

                            }
                        }

                        animatorStateSelected = EditorGUILayoutEx.CustomObjectPopup (guiContent, animatorStateSelected, animatorStateDisplayOptions, animatorStateValues);//,compare);

                        //TODO try Begin/End Check
                        if (animatorStateSelectedPrev != animatorStateSelected) {

                                NodePropertyIterator iter = property.serializedNode.GetIterator ();
                                iter.Find (attribute.layerIndexFieldName);
                                SerializedNodeProperty layerIndexSerialized = iter.current;

                                layerIndexSerialized.value = MecanimUtility.GetLayerIndex (aniController, animatorStateSelected);
                                layerIndexSerialized.ApplyModifiedValue ();

                                    ws.winx.unity.AnimatorState state=property.value as ws.winx.unity.AnimatorState;
                                    if(state==null) state=ScriptableObject.CreateInstance<ws.winx.unity.AnimatorState>();

                                    state.motion=animatorStateSelected.motion;
                                    state.nameHash=animatorStateSelected.nameHash;
                                    state.layer=(int)layerIndexSerialized.value;

                                    if(state.motion is UnityEditor.Animations.BlendTree){
                                        BlendTree tree =(BlendTree)state.motion;
                                        int blendParamsNum= tree.GetRecursiveBlendParamCount();

                                        state.blendParamsHashes=new int[blendParamsNum];

                                        for(int i=0;i<blendParamsNum;i++)
                                            state.blendParamsHashes[i]=Animator.StringToHash(tree.GetRecursiveBlendParam(i));

                                    }else{
                                            state.blendParamsHashes=null;
                                    }

                                    //property.value=state;
                                    property.ValueChanged();

                                property.ApplyModifiedValue ();

                                animatorStateSelectedPrev = animatorStateSelected;
                        }

                        if (animatorStateSelected.motion == null)
                                Debug.LogError ("Selected state doesn't have Motion set");
        }