示例#1
0
        public AnimatorCondition(PlayableAnimatorParameter parms, AssetCondition.Condition pData, int pIndex)
        {
            conditionData = pData;
            Index         = pIndex;

            mode      = conditionData.mode;
            threshold = conditionData.threshold;

            parameterData = parms.GetParameter(conditionData.parameter);

            switch (parameterData.type)
            {
            case AnimatorControllerParameterType.Int:
                conditionDelgate = GetConditionDelgate_Int();
                break;

            case AnimatorControllerParameterType.Float:
                conditionDelgate = GetConditionDelgate_Float();
                break;

            case AnimatorControllerParameterType.Bool:
                conditionDelgate = GetConditionDelgate_Bool();
                break;

            case AnimatorControllerParameterType.Trigger:
                conditionDelgate = GetConditionDelgate_Trigger();
                break;

            default:
                conditionDelgate = CheckConditionDelgate_Null;
                break;
            }
        }
        public AnimatorTransition(PlayableAnimatorParameter parms, AssetTransitions.Transtions pData, int pIndex)
        {
            AssetTransitions.Transtions transtion = pData;
            Index           = pIndex;
            duration        = transtion.duration;
            exitTime        = transtion.exitTime;
            destinationName = transtion.destinationName;
            destinationType = transtion.destinationType;


            if (transtion.conditions != null && transtion.conditions.Length > 0)
            {
                conditionLength = transtion.conditions.Length;
                conditions      = new AnimatorCondition[conditionLength];
                for (int i = 0; i < conditions.Length; i++)
                {
                    conditions[i] = new AnimatorCondition(parms, transtion.conditions[i], i);
                }
            }

            destinationHashName = destinationName.GetHashCode();
            ownerMachineIndex   = transtion.ownerMachineIndex;
        }
示例#3
0
        private void Initialize()
        {
            if (m_IsInitialized)
            {
                return;
            }

            if (!AnimationInstancingMgr.Instance.UseInstancing)
            {
                gameObject.SetActive(false);
                return;
            }
            Params         = new PlayableAnimatorParameter();
            worldTransform = transform;
            animator       = GetComponent <Animator>();
            boundingSpere  = new BoundingSphere(new Vector3(0, 0, 0), 1.0f);
            listAttachment = new List <AnimationInstancing>();
            layer          = gameObject.layer;

            switch (QualitySettings.skinWeights)
            {
            case SkinWeights.TwoBones:
                bonePerVertex = bonePerVertex > 2 ? 2 : bonePerVertex;
                break;

            case SkinWeights.OneBone:
                bonePerVertex = 1;
                break;
            }

            UnityEngine.Profiling.Profiler.BeginSample("Calculate lod");
            LODGroup lod = GetComponent <LODGroup>();

            if (lod != null)
            {
                lodInfo = new LodInfo[lod.lodCount];
                LOD[] lods = lod.GetLODs();
                for (int i = 0; i != lods.Length; ++i)
                {
                    if (lods[i].renderers == null)
                    {
                        continue;
                    }

                    LodInfo info = new LodInfo();
                    info.lodLevel          = i;
                    info.vertexCacheList   = new VertexCache[lods[i].renderers.Length];
                    info.materialBlockList = new MaterialBlock[info.vertexCacheList.Length];
                    List <SkinnedMeshRenderer> listSkinnedMeshRenderer = new List <SkinnedMeshRenderer>();
                    List <MeshRenderer>        listMeshRenderer        = new List <MeshRenderer>();
                    foreach (var render in lods[i].renderers)
                    {
                        if (render is SkinnedMeshRenderer)
                        {
                            listSkinnedMeshRenderer.Add((SkinnedMeshRenderer)render);
                        }
                        if (render is MeshRenderer)
                        {
                            listMeshRenderer.Add((MeshRenderer)render);
                        }
                    }
                    info.skinnedMeshRenderer = listSkinnedMeshRenderer.ToArray();
                    info.meshRenderer        = listMeshRenderer.ToArray();
                    //todo, to make sure whether the MeshRenderer can be in the LOD.
                    info.meshFilter = null;
                    for (int j = 0; j != lods[i].renderers.Length; ++j)
                    {
                        lods[i].renderers[j].enabled = false;
                    }
                    lodInfo[i] = info;
                }
            }
            else
            {
                lodInfo = new LodInfo[1];
                LodInfo info = new LodInfo();
                info.lodLevel            = 0;
                info.skinnedMeshRenderer = GetComponentsInChildren <SkinnedMeshRenderer>();
                info.meshRenderer        = GetComponentsInChildren <MeshRenderer>();
                info.meshFilter          = GetComponentsInChildren <MeshFilter>();
                info.vertexCacheList     = new VertexCache[info.skinnedMeshRenderer.Length + info.meshRenderer.Length];
                info.materialBlockList   = new MaterialBlock[info.vertexCacheList.Length];
                lodInfo[0] = info;

                for (int j = 0; j != info.meshRenderer.Length; ++j)
                {
                    info.meshRenderer[j].enabled = false;
                }
                for (int j = 0; j != info.skinnedMeshRenderer.Length; ++j)
                {
                    info.skinnedMeshRenderer[j].enabled = false;
                }
            }
            UnityEngine.Profiling.Profiler.EndSample();

            if (AnimationInstancingMgr.Instance.UseInstancing &&
                animator != null)
            {
                animator.enabled = false;
            }
            visible = true;
            CalcBoundingSphere();
            AnimationInstancingMgr.Instance.AddBoundingSphere(this);
            AnimationInstancingMgr.Instance.AddInstance(gameObject);

            m_IsInitialized = true;
        }