Beispiel #1
0
        private void ManagerControls()
        {
            _avatars = null != HasAvatars(SceneManager.GetActiveScene());

            // --- managers
            _managerOverload = ManagerSetup(EditorApplication.isPlaying, _play, _compile);

            // --- Avatar
            if (!EditorApplication.isPlaying)
            {
                newAvatars = GetAvatars(out bool crossScene);
            }
            if (null != manager && !EditorApplication.isPlaying && _avatars && (_play || _compile))
            {
                avatarIndex = 0;

                manager.Controllers = new List <RuntimeAnimatorController>();
                manager.LayerInfo   = new List <TEA_PlayableLayerData>();
                manager.ViewPorts   = new List <Vector3>();

                manager.Avatars = newAvatars.Keys.ToList <string>();
                TEA_Manager.AvatarDescriptor = newAvatars.Values.ToList <VRCAvatarDescriptor>();

                manager.SetupComponents(0);
                _patched = false;
            }
            else if (null != manager && EditorApplication.isPlaying && !_patched)
            {
                newAvatars = GetAvatars(out bool crossScene);
                TEA_Manager.AvatarDescriptor = newAvatars.Values.ToList <VRCAvatarDescriptor>();
                if (manager.Avatar == null)
                {
                    manager.Initialize(0);
                }
                manager.Settings = settings;
                manager.GetComponent <AvatarController>().Locomotion = settings;
                _patched = true;
            }

            // --- button presses
            if (!EditorApplication.isPlaying)
            {
                bool valid = true;
                if (_play || _compile)
                {
                    manager.gameObject.SetActive(false);
                    valid = compiler.CompileAnimators(manager, settings);
                    if (!_play && valid)
                    {
                        _play = EditorUtility.DisplayDialog($"Compilation", "Avatars Compiled", "Play", "Continue");
                    }
                    manager.gameObject.SetActive(!(!settings.keepInScene && !_play));
                    _compile = false;
                }
                if (_play)
                {
                    if (!compiler.validate || valid)
                    {
                        manager.Canvas.SetActive(true);
                        _compiled = true;
                        CheckAdditionalCamera();
                        EditorApplication.isPlaying = true;
                    }
                    _play = false;
                }
                else
                {
                    _compiled = false;
                }
            }
        }
Beispiel #2
0
	private static AnimatorController GenerateTEA_Animator(TEA_Manager manager) {
	 // --- TEA  ---
	 AnimatorController teaAnimContr = AssetDatabase.LoadAssetAtPath<AnimatorController>(AssetDatabase.GetAssetPath(manager.TEA_Animations));
	 while(teaAnimContr.layers.Length > 0) {
		teaAnimContr.RemoveLayer(0);
	 }
	 AnimatorStateMachine stateD = new AnimatorStateMachine();
	 teaAnimContr.AddLayer(new AnimatorControllerLayer() {
		name = AvatarController.TEA_HAND_LAYER,
		defaultWeight = 1,
		avatarMask = manager.AvatarMaskArms,
		stateMachine = stateD
	 });

	 //default
	 stateD.defaultState = stateD.AddState("Default");

	 manager.TEA_AnimationClips.ClearOptions();
	 List<Dropdown.OptionData> options = new List<Dropdown.OptionData>();

	 int count = 0;
	 List<AnimationClip> armClips = GetAnimationClips("Assets/TEA Manager/Resources/Animation/TEA Animations/TEA Hand Animations");
	 foreach(AnimationClip clip in armClips) {
		AnimatorState state = stateD.AddState(clip.name);
		state.motion = clip;
		stateD.defaultState.AddTransition(state).AddCondition(AnimatorConditionMode.Equals, count, AvatarController.TEA_ANIM_PARAM);
		state.AddExitTransition().AddCondition(AnimatorConditionMode.NotEqual, count, AvatarController.TEA_ANIM_PARAM);

		Dropdown.OptionData option = new Dropdown.OptionData(clip.name);
		options.Add(option);
		count++;
	 }//for

	 manager.GetComponent<AvatarController>().TEA_HAND_LAYER_COUNT = count;

	 // --- Full Body Animations
	 AnimatorStateMachine stateM = new AnimatorStateMachine();
	 teaAnimContr.AddLayer(new AnimatorControllerLayer() {
		name = AvatarController.TEA_LAYER,
		defaultWeight = 0,
		avatarMask = manager.AvatarMaskAll,
		stateMachine = stateM
	 });

	 stateM.defaultState = stateM.AddState("Default");

	 // dynamic
	 foreach(string folder in AssetDatabase.GetSubFolders("Assets/TEA Manager/Resources/Animation/TEA Animations")) {
		string name = folder.Substring(folder.LastIndexOf('/') + 1);
		if("TEA Hand Animations" == name)
		 continue;
		Dropdown.OptionData option = new Dropdown.OptionData(name);
		options.Add(option);
		AnimationClip start = null;
		AnimationClip loop = null;
		foreach(AnimationClip clip in GetAnimationClips(folder)) {
		 if(clip.name.Contains("intro") || clip.name.Contains("Intro")) {
			start = clip;
		 } else
			loop = clip;
		}//for
		AnimatorState state = stateM.AddState(name);
		state.motion = loop;
		if(null != start) {
		 AnimatorState startState = stateM.AddState(name + "-intro");
		 startState.motion = start;
		 stateM.defaultState.AddTransition(startState).AddCondition(AnimatorConditionMode.Equals, count, AvatarController.TEA_ANIM_PARAM);
		 startState.AddTransition(state).hasExitTime = true;
		} else {
		 stateM.defaultState.AddTransition(state).AddCondition(AnimatorConditionMode.Equals, count, AvatarController.TEA_ANIM_PARAM);
		}
		state.AddExitTransition().AddCondition(AnimatorConditionMode.NotEqual, count, AvatarController.TEA_ANIM_PARAM);
		count++;
	 }//for
	 manager.TEA_AnimationClips.AddOptions(options);
	 AssetDatabase.SaveAssets();
	 return teaAnimContr;
	}