Наследование: MonoBehaviour
Пример #1
0
    void MainMenu_PlayPreview()
    {
        previewIsPlaying = true;
        curCharacter = Instantiate(charactersList[selectedCharacter],Vector3.zero,Quaternion.identity) as Transform;
        curCharacter.name = charactersList[selectedCharacter].name;
        curCharacter.gameObject.AddComponent<AnimationBaker>();
        baker = curCharacter.GetComponent<AnimationBaker>();
        baker.dumpFilePath = dumpFilePath;
        if(useRootConstraints){
            baker.useRootConstraints = true;
            baker.rootPositionConstraint = rootPositionConstraints;
            baker.rootRotationConstraint = rootRotationConstraints;
            baker.rootScaleConstraint = rootScaleConstraints;
        }
        baker.playAnimation = true;

        if(mainCamera == null){
            mainCamera = Camera.main;
            if(mainCamera == null){
                GameObject dummy = new GameObject();
                dummy.AddComponent<Camera>();
                mainCamera = dummy.GetComponent<Camera>();
            }
        }
        mainCamera.transform.position = new Vector3(curCharacter.position.x,curCharacter.position.y+2f,curCharacter.position.z)+curCharacter.forward*100;
        mainCamera.transform.LookAt(curCharacter.position);
        mainCamera.orthographic = true;
        mainCamera.orthographicSize = 2f;
    }
Пример #2
0
    //==============================================================
    void ProcessNextCycle()
    {
        Debug.Log ("next cycle process, time:"+Time.time);
        AnimationBaker.cycleProcessed = false;
        if(curCharacter!=null){
            Destroy(curCharacter.gameObject);
        }
        if((curAnimationClipId== animationsList.Length-1) && (curCharacterId==charactersList.Length-1)){
            Debug.Log ("All stuff processed!");
            startRecord = false;
            EditorApplication.isPlaying = false;
            AssetDatabase.Refresh();
            return;
        }
        if(executionModeA){
            curAnimationClipId++;
            if(curCharacterId<0)
                curCharacterId = 0;
            if(curAnimationClipId>animationsList.Length-1){
                curAnimationClipId = 0;
                curCharacterId++;
            }
        }else{
            curCharacterId++;
            if(curAnimationClipId<0)
                curAnimationClipId = 0;
            if(curCharacterId>charactersList.Length-1){
                curCharacterId = 0;
                curAnimationClipId++;
            }
        }
        Debug.Log ("cur anim id:"+curAnimationClipId+" cur char id:"+curCharacterId);
        if(animationsList[curAnimationClipId].bakeForID[curCharacterId] == false){
            Debug.Log ("baking of '"+animationsList[curAnimationClipId].clip.name+"' skipped for "+charactersList[curCharacterId].transform.name);
            AnimationBaker.cycleProcessed = true;
            return;
        }
            Debug.Log ("create new character");
        lastStateName = "dummy";
            curCharacter = Instantiate(charactersList[curCharacterId],Vector3.zero,Quaternion.identity) as Transform;
            curCharacter.name = charactersList[curCharacterId].name;
                curCharacterName = curCharacter.name;
            _animator = curCharacter.GetComponent<Animator>();
            _animator.cullingMode = AnimatorCullingMode.AlwaysAnimate;
        if(baseController == null){
            baseController = AssetDatabase.LoadAssetAtPath("Assets/AnimationBaker/Core/aB_Animator.controller",typeof(RuntimeAnimatorController)) as RuntimeAnimatorController;
            Debug.Log ("baseController is empty, trying to load again...");
        }
            _animator.runtimeAnimatorController = baseController;
            AnimatorOverrideController oC = new AnimatorOverrideController();
            oC.runtimeAnimatorController = _animator.runtimeAnimatorController;
            oC[lastStateName] = animationsList[curAnimationClipId].clip;
            _animator.runtimeAnimatorController = oC;
            lastStateName = animationsList[curAnimationClipId].clip.name;
            curCharacter.gameObject.AddComponent<AnimationBaker>();
            baker = curCharacter.GetComponent<AnimationBaker>();
            baker.sourceAnimator = _animator;
            baker.samples = sampleRate;
            baker.isLegacyType = isLegacyType;
        if(modelNamePrefix)
            baker.clipNamePrefix +=curCharacter.name+"_";
        if(frameRatePrefix)
            baker.clipNamePrefix += sampleRate.ToString()+"_";
        if(!createDumpForAll)
            baker.createDumpFile = animationsList[curAnimationClipId].createDump;
        else
            baker.createDumpFile = createDumpForAll;
        if(!autoBakeDumpForAll)
            baker.dumpAutoBake = animationsList[curAnimationClipId].autoBakeDump;
        else
            baker.dumpAutoBake = autoBakeDumpForAll;
        if(animationsList[curAnimationClipId].recordTime<0)
            baker.recordTime = animationsList[curAnimationClipId].clip.length;
        else
            baker.recordTime = animationsList[curAnimationClipId].recordTime;
            baker.curAnimationName = lastStateName;
            baker.delayTime = delay;
            baker.delayPassedTime = 0f;
            baker.sourceAnimator.speed = 0f;
        //applying constraints================================
        if(useCommonBakingProperties)
            baker.bakingProperties = bakingProperties;
        else
            baker.bakingProperties = animationsList[curAnimationClipId].bakingProperties;
        if(useCommonRootConstraints){
            if(useRootConstraints){
                baker.rootPositionConstraint = rootPositionConstraints;
                baker.rootRotationConstraint = rootRotationConstraints;
                baker.rootScaleConstraint = rootScaleConstraints;
                baker.useRootConstraints = true;
            }else baker.useRootConstraints = false;
        }else if(animationsList[curAnimationClipId].useRootConstraints){
        baker.rootPositionConstraint = animationsList[curAnimationClipId].rootPositionConstraints;
        baker.rootRotationConstraint = animationsList[curAnimationClipId].rootRotationConstraints;
        baker.rootScaleConstraint = animationsList[curAnimationClipId].rootScaleConstraints;
        baker.useRootConstraints = true;
        }else baker.useRootConstraints = false;
        //====================================================
            baker.startRecord = true;

        if(mainCamera == null){
            mainCamera = Camera.main;
            if(mainCamera == null){
                GameObject dummy = new GameObject();
                dummy.AddComponent<Camera>();
                mainCamera = dummy.GetComponent<Camera>();
            }
        }
        mainCamera.transform.position = new Vector3(curCharacter.position.x,curCharacter.position.y+2f,curCharacter.position.z)+curCharacter.forward*100;
        mainCamera.transform.LookAt(curCharacter.position);
        mainCamera.orthographic = true;
        mainCamera.orthographicSize = 2f;
    }
Пример #3
0
 void BakeDump()
 {
     curCharacter = Instantiate(charactersList[selectedCharacter],Vector3.zero,Quaternion.identity) as Transform;
     curCharacter.name = charactersList[selectedCharacter].name;
     curCharacter.gameObject.AddComponent<AnimationBaker>();
     baker = curCharacter.GetComponent<AnimationBaker>();
     baker.LoadAnimationDump(dumpFilePath);
     if(useRootConstraints){
         baker.useRootConstraints = true;
         baker.rootPositionConstraint = rootPositionConstraints;
         baker.rootRotationConstraint = rootRotationConstraints;
         baker.rootScaleConstraint = rootScaleConstraints;
     }
     baker.bakingProperties = bakingProperties;
     baker.ConvertDumpToUnityAnimationFile();
     DestroyImmediate(curCharacter.gameObject);
 }