public static AnimatorController BuildAnimationController([NotNull] AnimationGroup group, [NotNull] string controllerName) { var controller = new AnimatorController(); controller.name = controllerName; controller.AddLayer(Layer0Name); controller.AddLayer(Layer1Name); controller.AddLayer(Layer2Name); controller.AddLayer(Layer3Name); controller.AddParameter(EnterSpecialAppeal, AnimatorControllerParameterType.Trigger); controller.AddParameter(ExitSpecialAppeal, AnimatorControllerParameterType.Trigger); controller.AddParameter(EnterAnotherAppeal, AnimatorControllerParameterType.Trigger); controller.AddParameter(ExitAnotherAppeal, AnimatorControllerParameterType.Trigger); controller.AddParameter(EnterGorgeousAppeal, AnimatorControllerParameterType.Trigger); controller.AddParameter(ExitGorgeousAppeal, AnimatorControllerParameterType.Trigger); var layers = controller.layers; { var states = layers[0].stateMachine; var s0 = states.AddState(DefaultStateName); states.defaultState = s0; s0.motion = group.mainMotion; } FillAppealStateMachine(layers[1], EnterSpecialAppeal, ExitSpecialAppeal, group.specialAppeal); FillAppealStateMachine(layers[2], EnterAnotherAppeal, ExitAnotherAppeal, group.anotherAppeal); FillAppealStateMachine(layers[3], EnterGorgeousAppeal, ExitGorgeousAppeal, group.gorgeousAppeal); return(controller); }
/// <summary> /// Creates the animator if needed /// </summary> /// <param name="rAnimatorController"></param> public static void SetupAnimatorController(AnimatorController rAnimatorController) { if (rAnimatorController.layers.Length < 1) { rAnimatorController.AddLayer("Base Layer"); rAnimatorController.layers[0].iKPass = true; } if (rAnimatorController.layers.Length < 2) { rAnimatorController.AddLayer("Upper Layer"); rAnimatorController.layers[1].iKPass = true; rAnimatorController.layers[1].avatarMask = AssetDatabase.LoadAssetAtPath <AvatarMask>("Assets/ootii/MotionController/Content/Animations/Upper.mask"); } if (rAnimatorController.layers.Length < 3) { rAnimatorController.AddLayer("Arms Only Layer"); rAnimatorController.layers[2].iKPass = true; rAnimatorController.layers[2].avatarMask = AssetDatabase.LoadAssetAtPath <AvatarMask>("Assets/ootii/MotionController/Content/Animations/ArmsOnly.mask"); } CreateAnimatorParameter(rAnimatorController, "L0MotionForm", AnimatorControllerParameterType.Int); CreateAnimatorParameter(rAnimatorController, "L1MotionForm", AnimatorControllerParameterType.Int); CreateAnimatorParameter(rAnimatorController, "L2MotionPhase", AnimatorControllerParameterType.Int); CreateAnimatorParameter(rAnimatorController, "L2MotionForm", AnimatorControllerParameterType.Int); CreateAnimatorParameter(rAnimatorController, "L2MotionParameter", AnimatorControllerParameterType.Int); CreateAnimatorParameter(rAnimatorController, "L2MotionStateTime", AnimatorControllerParameterType.Float); }
//创建AnimatorController static void CreateController() { string path = AnimatorSavePath + characterName + "/Set" + cur_set + "/Dynamic/Poster/Animation/" + characterName + AnimatorControllerSuffix; productController = AnimatorController.CreateAnimatorControllerAtPath(path); productController.layers = null; productController.AddLayer("Default"); productController.AddLayer("Face");//表情层 productController.parameters = null; var layers = productController.layers; layers[0].defaultWeight = 1; layers[0].blendingMode = AnimatorLayerBlendingMode.Override; layers[1].defaultWeight = 1; layers[1].blendingMode = AnimatorLayerBlendingMode.Additive; productController.layers = layers; // var layer = new UnityEditor.Animations.AnimatorControllerLayer // { // name = "Face", // defaultWeight = 1f, // blendingMode = AnimatorLayerBlendingMode.Additive, // stateMachine = new UnityEditor.Animations.AnimatorStateMachine() // Make sure to create a StateMachine as well, as a default one is not created // }; // productController.AddLayer("Face"); // productController.AddLayer(layer); }
private void CreateGestureLayer() { string layerName = generatedGestureName() + "Marker"; AnimatorControllerLayer layer = FindLayer(layerName); if (layer == null) { layer = new AnimatorControllerLayer(); layer.name = layerName; layer.defaultWeight = 1.0f; layer.stateMachine = new AnimatorStateMachine(); layer.stateMachine.name = layerName; layer.stateMachine.hideFlags = HideFlags.HideInHierarchy; if (AssetDatabase.GetAssetPath(fxController) != "") { AssetDatabase.AddObjectToAsset(layer.stateMachine, AssetDatabase.GetAssetPath(fxController)); } AnimatorState idleState = layer.stateMachine.AddState("Idle"); AnimatorState activateMarkerState = layer.stateMachine.AddState("Activate Marker"); AnimatorState eraseAllState = layer.stateMachine.AddState("Erase All"); //set the idle transition for (int i = 0; i < 8; i++) { if (i == (int)activateGesture) { AnimatorStateTransition transition; transition = layer.stateMachine.AddAnyStateTransition(activateMarkerState); SetGestureTransitionDefaults(transition); transition.AddCondition(AnimatorConditionMode.Equals, i, generatedGestureName()); } else if (i == (int)resetGesture) { AnimatorStateTransition transition; transition = layer.stateMachine.AddAnyStateTransition(eraseAllState); SetGestureTransitionDefaults(transition); transition.AddCondition(AnimatorConditionMode.Equals, i, generatedGestureName()); } else { AnimatorStateTransition transition; transition = layer.stateMachine.AddAnyStateTransition(idleState); SetGestureTransitionDefaults(transition); transition.AddCondition(AnimatorConditionMode.Equals, i, generatedGestureName()); } } WriteGestureAnimations(); idleState.motion = idleClip; activateMarkerState.motion = drawOnClip; eraseAllState.motion = eraseOnClip; fxController.AddLayer(layer); } }
private void CreateGestureLayer() { string layerName = generatedGestureName() + "Maker"; AnimatorControllerLayer layer = FindLayer(layerName); if (layer == null) { layer = new AnimatorControllerLayer(); layer.name = layerName; layer.defaultWeight = 1.0f; layer.stateMachine = new AnimatorStateMachine(); layer.stateMachine.name = layerName; layer.stateMachine.hideFlags = HideFlags.HideInHierarchy; if (AssetDatabase.GetAssetPath(fxController) != "") { AssetDatabase.AddObjectToAsset(layer.stateMachine, AssetDatabase.GetAssetPath(fxController)); } AnimatorState idleState = layer.stateMachine.AddState("Idle"); AnimatorState activateMarkerState = layer.stateMachine.AddState("Activate Marker"); AnimatorState eraseAllState = layer.stateMachine.AddState("Erase All"); for (int i = 0; i < 8; i++) { AnimatorStateTransition transition; if (i == (int)activateGesture) { transition = layer.stateMachine.AddAnyStateTransition(activateMarkerState); } else if (i == (int)resetGesture) { transition = layer.stateMachine.AddAnyStateTransition(eraseAllState); } else { transition = layer.stateMachine.AddAnyStateTransition(idleState); } transition.AddCondition(AnimatorConditionMode.Equals, i, generatedGestureName()); transition.hasExitTime = false; transition.hasFixedDuration = false; transition.duration = .1f; transition.interruptionSource = TransitionInterruptionSource.Destination; transition.canTransitionToSelf = false; } WriteGestureAnimations(); activateMarkerState.motion = drawClip; eraseAllState.motion = eraseClip; idleState.motion = resetClip; fxController.AddLayer(layer); } }
private void CombineAnimator(AnimatorController superAnimator, AnimatorController animator, AvatarMask mask) { if(null == animator || null == superAnimator) return; foreach(AnimatorControllerParameter param in animator.parameters) { if(!string.IsNullOrEmpty(param.name) && !HasAnimatorParameter(superAnimator, param.name)) superAnimator.AddParameter(param); } foreach(AnimatorControllerLayer layer in animator.layers) { //Debug.Log($"combining [{superAnimator.name}] with [{animator.name}] layer[{layer.name}]"); AnimatorControllerLayer newLayer = new AnimatorControllerLayer { avatarMask = null == mask ? layer.avatarMask : mask, name = layer.name, blendingMode = layer.blendingMode, defaultWeight = layer.defaultWeight, iKPass = layer.iKPass, stateMachine = layer.stateMachine, syncedLayerAffectsTiming = layer.syncedLayerAffectsTiming, syncedLayerIndex = layer.syncedLayerIndex }; superAnimator.AddLayer(newLayer); } //Debug.Log("-----------"); }
public void CreateItemAnimatorFromPlayerAnimator(int itemID, Animator playerAnimator) { if (itemID >= 0) { hasItemEquipped = true; var newController = new AnimatorController { name = "newController" }; newController.AddLayer( newController.MakeUniqueLayerName("BaseLayer")); AddPlayerAnimatorParametersToNewController( playerAnimator, newController); AddPlayerAnimatorStatesToNewController( playerAnimator, newController, itemID); AddPlayerAnimatorTransitionsToNewController( playerAnimator, newController); GetComponent <Animator>().runtimeAnimatorController = newController; } else { hasItemEquipped = false; GetComponent <Animator>().runtimeAnimatorController = null; } }
/// <summary> /// Show how to create a controller, and set layer parameters /// </summary> private void CreateController() { productController = AnimatorController.CreateAnimatorControllerAtPath(AnimatorSavePath + characterName + AnimatorControllerSuffix); // get base machine in base layer baseLayerMachine = productController.layers[0].stateMachine; // set base machine parameters baseLayerMachine.entryPosition = Vector3.zero; baseLayerMachine.exitPosition = new Vector3(400f, 200f); baseLayerMachine.anyStatePosition = new Vector3(0f, 200f); // add crouch layer to controller productController.AddLayer("CrouchLayer"); // get a copy from controller's layer AnimatorControllerLayer[] layers = productController.layers; // set layer parameters layers[1].defaultWeight = 1f; layers[1].blendingMode = AnimatorLayerBlendingMode.Override; // save layer setting to controller productController.layers = layers; // get state machine in crouch layer crouchLayerMachine = productController.layers[1].stateMachine; // set crouch machine parameters crouchLayerMachine.entryPosition = Vector3.zero; crouchLayerMachine.exitPosition = new Vector3(600f, 200f); crouchLayerMachine.anyStatePosition = new Vector3(0f, 200f); }
void CreateAnimator(string path) { targetController = new AnimatorController(); try { AssetDatabase.CreateAsset(targetController, "Assets/Resource/" + path + ".controller"); } catch { Debug.Log("path Error!! 경로를 확인해 주세요"); targetController = null; return; } targetController.AddLayer("base"); AnimatorControllerParameter param = new AnimatorControllerParameter(); param.type = AnimatorControllerParameterType.Float; param.defaultFloat = 1f; param.name = "SpeedParam"; targetController.AddParameter(param); targetController.AddParameter("State", AnimatorControllerParameterType.Int); targetController.AddParameter("WeaponNumber", AnimatorControllerParameterType.Int); targetController.AddParameter("ComboCount", AnimatorControllerParameterType.Int); targetController.AddParameter("OneShot", AnimatorControllerParameterType.Trigger); AnimatorControllerParameter maxViewParam = new AnimatorControllerParameter(); maxViewParam.type = AnimatorControllerParameterType.Int; maxViewParam.defaultInt = directionCount; maxViewParam.name = "maxView"; targetController.AddParameter(maxViewParam); AssetDatabase.SaveAssets(); AssetDatabase.Refresh(); }
private bool GetAnimator(string animationName) { bool alreadyExists; string controllerPath = ""; string[] temp = AssetDatabase.FindAssets(string.Concat("t:AnimatorController ", animationName)); controllerPath = string.Concat("Assets/Resources/Animation/Controllers/" + animationName + ".controller"); if (temp.Length > 0) { animationControl = (AnimatorController)AssetDatabase.LoadAssetAtPath(controllerPath, typeof(AnimatorController)); alreadyExists = true; } else { AssetDatabase.CreateAsset(new AnimatorController(), controllerPath); animationControl = (AnimatorController)AssetDatabase.LoadAssetAtPath(controllerPath, typeof(AnimatorController)); animationControl.AddLayer("New Layer"); alreadyExists = false; } for (int i = 0; i < animationControl.layers.Length; i++) { ChildAnimatorState[] states = animationControl.layers[i].stateMachine.states; for (int j = 0; j < states.Length; j++) { AnimationClip ac = (AnimationClip)states[j].state.motion; } } return(alreadyExists); }
private AnimatorController CreateAnimatorController() { if (!Directory.Exists(m_xmlSetting.SavePath)) { Directory.CreateDirectory(m_xmlSetting.SavePath); } if (string.IsNullOrEmpty(m_xmlSetting.SaveName)) { StringBuilder strMD5 = new StringBuilder(); MD5 md5Provider = new MD5CryptoServiceProvider(); byte[] outputHash = md5Provider.ComputeHash(Encoding.Default.GetBytes(DateTime.Now.ToString())); for (int i = 0; i < outputHash.Length; i++) { strMD5.Append(outputHash[i].ToString("X")); } m_xmlSetting.SaveName = strMD5.ToString(); } AnimatorController ac = AnimatorController.CreateAnimatorControllerAtPath(m_xmlSetting.SavePath + "/" + m_xmlSetting.SaveName + ".controller"); ac.AddLayer("Up Layer"); //每层添加空状态 if (m_xmlSetting.bSetEmptyState) { for (int i = 0; i < ac.layers.Length; i++) { AddDefaultState(ac, i); } } return(ac); }
private void CreateStateMachine() { if (avatarPreview == null || avatarPreview.Animator == null) { return; } if (controller == null) { controller = new AnimatorController(); controller.hideFlags = HideFlags.DontSave; controller.AddLayer("preview"); stateMachine = controller.layers[0].stateMachine; CreateParameters(); state = stateMachine.AddState("preview"); state.motion = previewedMotion; state.iKOnFeet = avatarPreview.IKOnFeet; state.hideFlags = HideFlags.DontSave; stateMachine.hideFlags = HideFlags.DontSave; AnimatorController.SetAnimatorController(avatarPreview.Animator, controller); controller.AppendOnAnimatorControllerDirtyCallback(ControllerDitry); controllerIsDitry = false; } if (AnimatorControllerExtension.GetEffectiveAnimatorController(avatarPreview.Animator) != controller) { AnimatorController.SetAnimatorController(avatarPreview.Animator, controller); } }
public void It_should_set_an_Animator_int() { var fsm = Substitute.For <IFsm>(); fsm.Owner.Returns(_go); var state = Substitute.For <IState>(); state.ParentFsm.Returns(fsm); var param = new AnimatorControllerParameter { name = "a", type = AnimatorControllerParameterType.Float }; var animator = _go.AddComponent <Animator>(); var animatorCtrl = new AnimatorController { parameters = new[] { param } }; animatorCtrl.AddLayer("Default"); animator.runtimeAnimatorController = animatorCtrl; var action = new ActionSetAnimatorFloat("a", 1) { ParentState = state }; action.Enter(); Assert.AreEqual(1, animator.GetFloat("a")); }
static void CreateAnimator(string[] files) { string path = new System.Text.StringBuilder().Append(@Application.streamingAssetsPath).Append('/').Append(AppConst.TextDir).Append('/').ToString(); EditorUtil.Init <AnimatorInfo>(path); EditorUtil.Init <AnimatorTransInfo>(path); EditorUtil.Init <AnimatorTransfer>(path); int width = 250; int height = 50; for (int i = 0; i < files.Length; i++) { string pName = Path.GetFileNameWithoutExtension(files[i]); AnimatorController controller = AnimatorController.CreateAnimatorControllerAtPath(AppConst.AssetPath + "/Animator/" + pName + ".controller"); AnimatorControllerLayer currLayer = null; if (controller.layers.Length > 0) { currLayer = controller.layers[0]; } else { currLayer = new AnimatorControllerLayer(); currLayer.name = "Base Layer"; controller.AddLayer(currLayer); } currLayer.stateMachine.anyStatePosition = new Vector3(0, height * 3, 0); currLayer.stateMachine.entryPosition = new Vector3(0, height, 0); currLayer.stateMachine.exitPosition = new Vector3(((int)AnimatState.AnimaState_MAX / 5 + 1) * width, height * 3, 0); AddAnimatorState(controller, currLayer, width, height, pName); AddParameters(controller); AddTransition(currLayer); } }
private void InsertLayer(AnimatorController controller, AnimatorControllerLayer layer, int toIndex) { var fromIndex = Array.IndexOf(controller.layers.Select(x => x.name).ToArray(), layer.name); if (fromIndex == -1) { controller.AddLayer(layer); fromIndex = controller.layers.Length - 1; } if (fromIndex == toIndex) return; var layers = controller.layers; var insert = layers[fromIndex]; var di = fromIndex > toIndex ? 1 : -1; int i = toIndex; while(i >= 0 && i < layers.Length) { var work = layers[i]; layers[i] = insert; insert = work; if (i == fromIndex) break; i += di; } controller.layers = layers; AssetDatabase.SaveAssets(); }
void Start() { anim = GetComponent <Animator>(); // Creates the controller controller = new AnimatorController(); controller.AddParameter("Go to A2", AnimatorControllerParameterType.Trigger); controller.AddParameter("Go to A1", AnimatorControllerParameterType.Trigger); controller.AddLayer("nakedLayer"); // Add StateMachines var rootStateMachine = controller.layers[0].stateMachine; //var stateMachineA = rootStateMachine.AddStateMachine("smA"); anim.runtimeAnimatorController = controller; dbcon = ScriptableObject.CreateInstance("dbConnector") as dbConnector; dbcon.LoadStuff(); pathReader = ScriptableObject.CreateInstance("PathReader") as PathReader; pathReader.Initialize(); mocapLoader = ScriptableObject.CreateInstance("MocapLoader") as MocapLoader; mocapLoader.Initialize(rootStateMachine); }
/// <summary> /// Sets all fields and properties that have been deserialized. /// </summary> /// <param name="obj">The GameObject that will be used to initialize this component.</param> /// <param name="info">The fields that were deserialized already.</param> /// <param name="context">A context container that stores a <see cref="XmlDeserializer.DeserializeContext"/> object within.</param> /// <param name="selector">Always null.</param> /// <returns>The component that was deserialized.</returns> public override object SetObjectData(object obj, SerializationInfo info, StreamingContext context, ISurrogateSelector selector) { //just deserialize as normal in-place object //ReplaceState(obj, info); if (obj == null) { return(null); } AnimatorController con = obj as AnimatorController; var layers = info.GetValue("layers", typeof(AnimatorControllerLayer[])) as AnimatorControllerLayer[]; //con.layers = layers as AnimatorControllerLayer[]; if (con.layers == null && layers != null) { Debug.LogError("Failed to deserialize 'AnimatorController.layers' properly."); } con.hideFlags = (HideFlags)info.GetInt32("hideFlags"); con.name = info.GetString("name"); con.parameters = info.GetValue("parameters", typeof(AnimatorControllerParameter[])) as AnimatorControllerParameter[]; int i = 0; foreach (var layer in layers) { Debug.Log("Add layer: " + layer.name); con.AddLayer(layer.name); foreach (var state in layer.stateMachine.states) { con.layers[i].stateMachine.AddState(state.state.name, state.position); } i++; } return(obj); }
/// <summary> /// Creates a Unity sprite animation from the given <see cref="Layer"/> that is a group layer. It grabs all of the children art /// layers and uses them as the frames of the animation. /// </summary> /// <param name="layer">The group <see cref="Layer"/> to use to create the sprite animation.</param> private static void CreateAnimation(Layer layer) { float fps = 30; string[] args = layer.Name.Split(new[] { '|' }, StringSplitOptions.RemoveEmptyEntries); foreach (string arg in args) { if (arg.ContainsIgnoreCase("FPS=")) { layer.Name = layer.Name.Replace("|" + arg, string.Empty); string[] fpsArgs = arg.Split(new[] { '=' }, StringSplitOptions.RemoveEmptyEntries); if (!float.TryParse(fpsArgs[1], out fps)) { Debug.LogError(string.Format("Unable to parse FPS: \"{0}\"", arg)); } } } List <Sprite> frames = new List <Sprite>(); Layer firstChild = layer.Children.First(); SpriteRenderer spriteRenderer = CreateSpriteGameObject(firstChild); spriteRenderer.name = layer.Name; foreach (Layer child in layer.Children) { frames.Add(CreateSprite(child, layer.Name)); } spriteRenderer.sprite = frames[0]; #if UNITY_5 // Create Animator Controller with an Animation Clip UnityEditor.Animations.AnimatorController controller = new UnityEditor.Animations.AnimatorController(); controller.AddLayer("Base Layer"); UnityEditor.Animations.AnimatorControllerLayer controllerLayer = controller.layers[0]; UnityEditor.Animations.AnimatorState state = controllerLayer.stateMachine.AddState(layer.Name); state.motion = CreateSpriteAnimationClip(layer.Name, frames, fps); AssetDatabase.CreateAsset(controller, GetRelativePath(currentPath) + "/" + layer.Name + ".controller"); #else // Unity 4 // Create Animator Controller with an Animation Clip AnimatorController controller = new AnimatorController(); AnimatorControllerLayer controllerLayer = controller.AddLayer("Base Layer"); State state = controllerLayer.stateMachine.AddState(layer.Name); state.SetAnimationClip(CreateSpriteAnimationClip(layer.Name, frames, fps)); AssetDatabase.CreateAsset(controller, GetRelativePath(currentPath) + "/" + layer.Name + ".controller"); #endif // Add an Animator and assign it the controller Animator animator = spriteRenderer.gameObject.AddComponent <Animator>(); animator.runtimeAnimatorController = controller; }
private static AnimatorController CreateAnimatorController(VRCAvatarDescriptor avatar, List <AnimationClip> animations) { var dest = EditorUtility.SaveFilePanelInProject("Save Copied Animator Controller to...", "NewAnimatorController", "controller", ""); if (string.IsNullOrWhiteSpace(dest)) { return(null); } var controller = new AnimatorController(); AssetDatabase.CreateAsset(controller, dest); if (avatar.customizeAnimationLayers && avatar.HasAnimationLayer(VRCAvatarDescriptor.AnimLayerType.FX, false)) { controller.MergeControllers((AnimatorController)avatar.GetAnimationLayer(VRCAvatarDescriptor.AnimLayerType.FX).animatorController); } if (controller.HasLayer(InternalName)) { AssetDatabase.SaveAssets(); return(controller); } controller.AddParameter(InternalName, AnimatorControllerParameterType.Bool); controller.AddLayer(InternalName); var layer = controller.GetLayer(InternalName); layer.defaultWeight = 1.0f; controller.SetLayer(InternalName, layer); var stateMachine = layer.stateMachine; var deactivationState = stateMachine.AddState("Deactivation"); deactivationState.motion = animations[1]; deactivationState.writeDefaultValues = false; deactivationState.AddExitTransition(true); var activationState = stateMachine.AddState("Activation"); activationState.motion = animations[0]; activationState.writeDefaultValues = false; var transitionFromAny = stateMachine.AddAnyStateTransition(activationState); transitionFromAny.AddCondition(AnimatorConditionMode.If, 1.0f, InternalName); // true var transitionToDeactivation = activationState.AddTransition(deactivationState); transitionToDeactivation.AddCondition(AnimatorConditionMode.IfNot, 1.0f, InternalName); // false transitionToDeactivation.hasExitTime = false; AssetDatabase.SaveAssets(); return(controller); }
void OnValidate() { if (Application.isPlaying) { return; } AnimatorController preview = Animator.runtimeAnimatorController as AnimatorController; if (!preview || preview.name != "UIPlayable Preview") { preview = new AnimatorController(); preview.name = "UIPlayable Preview"; preview.hideFlags = HideFlags.DontSave; preview.AddLayer("Base Layer"); preview.AddLayer("Preview Layer"); preview.layers[1].defaultWeight = 0; Animator.runtimeAnimatorController = preview; } foreach (var childAnimatorState in preview.layers[1].stateMachine.states) { var animatorState = childAnimatorState.state; bool exist = States.Any(state => state.Animation == animatorState.motion || state.LoopAnimation == animatorState.motion); if (!exist) { preview.RemoveLayer(1); preview.AddLayer("Preview Layer"); preview.layers[1].defaultWeight = 0; break; } } foreach (State state in States) { if (state.Animation) { AddMotionIfNotExist(preview, state.Animation); } if (state.LoopAnimation) { AddMotionIfNotExist(preview, state.LoopAnimation); } } }
void AddLayerMounted(AnimatorController AnimController) { AnimatorController MountedLayerFile = Resources.Load <AnimatorController>("Mounted Layer"); AnimatorControllerLayer MountedLayer = MountedLayerFile.layers[1]; UpdateParametersOnAnimator(AnimController); AnimController.AddLayer(MountedLayer); }
public static AnimatorController CreateAnimatorControllerAtPath(string path) { AnimatorController animatorController = new AnimatorController(); animatorController.name = Path.GetFileName(path); animatorController.AddLayer("Base Layer"); AssetDatabase.CreateAsset(animatorController, path); return(animatorController); }
void AddLayerMountedCombat(AnimatorController CurrentAnimator) { AnimatorController MountedLayerFile = Resources.Load <AnimatorController>("Mounted Layer"); Rider3rdPersonEditor.UpdateParametersOnAnimator(CurrentAnimator); UpdateParametersOnAnimator(CurrentAnimator); //Adding the Parameters Needed AnimatorControllerLayer RiderCombatLayers = MountedLayerFile.layers[2]; //Search For the 2nd Layer to Add CurrentAnimator.AddLayer(RiderCombatLayers); //Add "Rider Arm Right" Layer RiderCombatLayers = MountedLayerFile.layers[3]; CurrentAnimator.AddLayer(RiderCombatLayers); //Add "Rider Arm Left" Layer RiderCombatLayers = MountedLayerFile.layers[4]; CurrentAnimator.AddLayer(RiderCombatLayers); //Add "Rider Combat" Layer }
public static AnimatorController MergeControllers(AnimatorController mainController, AnimatorController controllerToMerge, Dictionary <string, string> paramNameSwap = null, bool saveToNew = false) { if (mainController == null) { return(null); } _parametersNewName = paramNameSwap ?? new Dictionary <string, string>(); _assetPath = AssetDatabase.GetAssetPath(mainController); if (saveToNew) { Directory.CreateDirectory("Assets/VRLabs/GeneratedAssets"); string uniquePath = AssetDatabase.GenerateUniqueAssetPath(STANDARD_NEW_ANIMATOR_FOLDER + Path.GetFileName(_assetPath)); AssetDatabase.CopyAsset(_assetPath, uniquePath); AssetDatabase.SaveAssets(); AssetDatabase.Refresh(); _assetPath = uniquePath; mainController = AssetDatabase.LoadAssetAtPath <AnimatorController>(_assetPath); } if (controllerToMerge == null) { return(mainController); } foreach (var p in controllerToMerge.parameters) { var newP = new AnimatorControllerParameter { name = _parametersNewName.ContainsKey(p.name) ? _parametersNewName[p.name] : p.name, type = p.type, defaultBool = p.defaultBool, defaultFloat = p.defaultFloat, defaultInt = p.defaultInt }; if (mainController.parameters.Count(x => x.name.Equals(newP.name)) == 0) { mainController.AddParameter(newP); } } for (int i = 0; i < controllerToMerge.layers.Length; i++) { AnimatorControllerLayer newL = CloneLayer(controllerToMerge.layers[i], i == 0); newL.name = MakeLayerNameUnique(newL.name, mainController); newL.stateMachine.name = newL.name; mainController.AddLayer(newL); } EditorUtility.SetDirty(mainController); AssetDatabase.SaveAssets(); AssetDatabase.Refresh(); return(mainController); }
/// <summary> /// 1個のAnitionClipを再生するだけの AnimatorController を作成する /// </summary> /// <param name="clip"></param> /// <returns></returns> public static RuntimeAnimatorController CreateAnimatorControllerWithClip(AnimationClip clip) { var animatorController = new AnimatorController(); animatorController.AddLayer("main"); animatorController.AddMotion(clip); EditorUtility.SetDirty(animatorController); return(animatorController); }
private void ReplaceLayer(AnimatorController controller, AnimationClip[] clipList = null) { controller.RemoveLayer(0); controller.AddLayer("Base Layer"); if (clipList != null) { for (int i = 0; i < clipList.Length; i++) { controller.AddMotion(clipList[i]); } } }
internal void SwitchToEditMode() { this.m_EditMode = AvatarEditor.EditMode.Starting; this.ChangeInspectorLock(true); this.sceneSetup = EditorSceneManager.GetSceneManagerSetup(); EditorSceneManager.NewScene(NewSceneSetup.DefaultGameObjects).name = "Avatar Configuration"; this.m_GameObject = UnityEngine.Object.Instantiate <GameObject>(this.prefab); if (base.serializedObject.FindProperty("m_OptimizeGameObjects").boolValue) { AnimatorUtility.DeoptimizeTransformHierarchy(this.m_GameObject); } Animator component = this.m_GameObject.GetComponent <Animator>(); if (component != null && component.runtimeAnimatorController == null) { AnimatorController animatorController = new AnimatorController(); animatorController.hideFlags = HideFlags.DontSave; animatorController.AddLayer("preview"); animatorController.layers[0].stateMachine.hideFlags = HideFlags.DontSave; component.runtimeAnimatorController = animatorController; } Dictionary <Transform, bool> modelBones = AvatarSetupTool.GetModelBones(this.m_GameObject.transform, true, null); AvatarSetupTool.BoneWrapper[] humanBones = AvatarSetupTool.GetHumanBones(base.serializedObject, modelBones); this.m_ModelBones = AvatarSetupTool.GetModelBones(this.m_GameObject.transform, false, humanBones); Selection.activeObject = this.m_GameObject; UnityEngine.Object[] array = Resources.FindObjectsOfTypeAll(typeof(SceneHierarchyWindow)); for (int i = 0; i < array.Length; i++) { SceneHierarchyWindow sceneHierarchyWindow = (SceneHierarchyWindow)array[i]; sceneHierarchyWindow.SetExpandedRecursive(this.m_GameObject.GetInstanceID(), true); } this.CreateEditor(); this.m_EditMode = AvatarEditor.EditMode.Editing; this.m_SceneStates = new List <AvatarEditor.SceneStateCache>(); foreach (SceneView sceneView in SceneView.sceneViews) { this.m_SceneStates.Add(new AvatarEditor.SceneStateCache { state = new SceneView.SceneViewState(sceneView.m_SceneViewState), view = sceneView }); sceneView.m_SceneViewState.showFlares = false; sceneView.m_SceneViewState.showMaterialUpdate = false; sceneView.m_SceneViewState.showFog = false; sceneView.m_SceneViewState.showSkybox = false; sceneView.m_SceneViewState.showImageEffects = false; sceneView.FrameSelected(); } }
private static AnimatorController CreateControllerFromClip(AnimationClip clip) { var tempClip = clip; tempClip.wrapMode = WrapMode.Loop; var controller = new AnimatorController(); controller.name = "TestController"; controller.AddLayer("Base"); controller.layers[0].stateMachine.AddState(tempClip.name); controller.layers[0].stateMachine.states[0].state.motion = tempClip; return(controller); }
public int AddLayer(string layerName) { animatorController.AddLayer(layerName); for (int i = 0; i < animatorController.layers.Length; i++) { if (animatorController.layers[i].name == layerName) { return(i); } } return(-1); }
private AnimatorControllerLayer CreateLayer(AnimatorController animator, string layerName) { AnimatorControllerLayer layer = new AnimatorControllerLayer(); layer.name = layerName; AnimatorStateMachine stateMachine = new AnimatorStateMachine(); stateMachine.name = layer.name; AssetDatabase.AddObjectToAsset(stateMachine, animator); stateMachine.hideFlags = HideFlags.HideInHierarchy; layer.stateMachine = stateMachine; animator.AddLayer(layer); return(layer); }
/// <summary> /// Creates a Unity sprite animation from the given <see cref="Layer"/> that is a group layer. It grabs all of the children art /// layers and uses them as the frames of the animation. /// </summary> /// <param name="layer">The group <see cref="Layer"/> to use to create the sprite animation.</param> private static void CreateAnimation(Layer layer) { float fps = 30; string[] args = layer.Name.Split(new[] { '|' }, StringSplitOptions.RemoveEmptyEntries); foreach (string arg in args) { if (arg.ContainsIgnoreCase("FPS=")) { layer.Name = layer.Name.Replace("|" + arg, string.Empty); string[] fpsArgs = arg.Split(new[] { '=' }, StringSplitOptions.RemoveEmptyEntries); if (!float.TryParse(fpsArgs[1], out fps)) { Debug.LogError(string.Format("Unable to parse FPS: \"{0}\"", arg)); } } } List<Sprite> frames = new List<Sprite>(); Layer firstChild = layer.Children.First(); SpriteRenderer spriteRenderer = CreateSpriteGameObject(firstChild); spriteRenderer.name = layer.Name; foreach (Layer child in layer.Children) { frames.Add(CreateSprite(child, layer.Name)); } spriteRenderer.sprite = frames[0]; #if UNITY_5 // Create Animator Controller with an Animation Clip UnityEditor.Animations.AnimatorController controller = new UnityEditor.Animations.AnimatorController(); controller.AddLayer("Base Layer"); UnityEditor.Animations.AnimatorControllerLayer controllerLayer = controller.layers[0]; UnityEditor.Animations.AnimatorState state = controllerLayer.stateMachine.AddState(layer.Name); state.motion = CreateSpriteAnimationClip(layer.Name, frames, fps); AssetDatabase.CreateAsset(controller, GetRelativePath(currentPath) + "/" + layer.Name + ".controller"); #else // Unity 4 // Create Animator Controller with an Animation Clip AnimatorController controller = new AnimatorController(); AnimatorControllerLayer controllerLayer = controller.AddLayer("Base Layer"); State state = controllerLayer.stateMachine.AddState(layer.Name); state.SetAnimationClip(CreateSpriteAnimationClip(layer.Name, frames, fps)); AssetDatabase.CreateAsset(controller, GetRelativePath(currentPath) + "/" + layer.Name + ".controller"); #endif // Add an Animator and assign it the controller Animator animator = spriteRenderer.gameObject.AddComponent<Animator>(); animator.runtimeAnimatorController = controller; }
internal void SwitchToEditMode() { this.m_EditMode = AvatarEditor.EditMode.Starting; this.ChangeInspectorLock(true); this.sceneSetup = EditorSceneManager.GetSceneManagerSetup(); EditorSceneManager.NewScene(NewSceneSetup.DefaultGameObjects); this.m_GameObject = UnityEngine.Object.Instantiate<GameObject>(this.prefab); if (this.serializedObject.FindProperty("m_OptimizeGameObjects").boolValue) AnimatorUtility.DeoptimizeTransformHierarchy(this.m_GameObject); Animator component = this.m_GameObject.GetComponent<Animator>(); if ((UnityEngine.Object) component != (UnityEngine.Object) null && (UnityEngine.Object) component.runtimeAnimatorController == (UnityEngine.Object) null) { AnimatorController animatorController = new AnimatorController(); animatorController.hideFlags = HideFlags.DontSave; animatorController.AddLayer("preview"); animatorController.layers[0].stateMachine.hideFlags = HideFlags.DontSave; component.runtimeAnimatorController = (RuntimeAnimatorController) animatorController; } this.m_ModelBones = AvatarSetupTool.GetModelBones(this.m_GameObject.transform, false, AvatarSetupTool.GetHumanBones(this.serializedObject, AvatarSetupTool.GetModelBones(this.m_GameObject.transform, true, (AvatarSetupTool.BoneWrapper[]) null))); Selection.activeObject = (UnityEngine.Object) this.m_GameObject; foreach (SceneHierarchyWindow sceneHierarchyWindow in Resources.FindObjectsOfTypeAll(typeof (SceneHierarchyWindow))) sceneHierarchyWindow.SetExpandedRecursive(this.m_GameObject.GetInstanceID(), true); this.CreateEditor(); this.m_EditMode = AvatarEditor.EditMode.Editing; this.m_SceneStates = new List<AvatarEditor.SceneStateCache>(); foreach (SceneView sceneView in SceneView.sceneViews) { this.m_SceneStates.Add(new AvatarEditor.SceneStateCache() { state = new SceneView.SceneViewState(sceneView.m_SceneViewState), view = sceneView }); sceneView.m_SceneViewState.showFlares = false; sceneView.m_SceneViewState.showMaterialUpdate = false; sceneView.m_SceneViewState.showFog = false; sceneView.m_SceneViewState.showSkybox = false; sceneView.FrameSelected(); } }
internal void SwitchToEditMode() { this.m_EditMode = AvatarEditor.EditMode.Starting; this.ChangeInspectorLock(true); this.m_UserFileName = EditorApplication.currentScene; EditorApplication.NewScene(); this.m_GameObject = UnityEngine.Object.Instantiate<GameObject>(this.prefab); if (base.serializedObject.FindProperty("m_OptimizeGameObjects").boolValue) { AnimatorUtility.DeoptimizeTransformHierarchy(this.m_GameObject); } Animator component = this.m_GameObject.GetComponent<Animator>(); if (component != null && component.runtimeAnimatorController == null) { AnimatorController animatorController = new AnimatorController(); animatorController.hideFlags = HideFlags.DontSave; animatorController.AddLayer("preview"); component.runtimeAnimatorController = animatorController; } Dictionary<Transform, bool> modelBones = AvatarSetupTool.GetModelBones(this.m_GameObject.transform, true, null); AvatarSetupTool.BoneWrapper[] humanBones = AvatarSetupTool.GetHumanBones(base.serializedObject, modelBones); this.m_ModelBones = AvatarSetupTool.GetModelBones(this.m_GameObject.transform, false, humanBones); Selection.activeObject = this.m_GameObject; UnityEngine.Object[] array = Resources.FindObjectsOfTypeAll(typeof(SceneHierarchyWindow)); for (int i = 0; i < array.Length; i++) { SceneHierarchyWindow sceneHierarchyWindow = (SceneHierarchyWindow)array[i]; sceneHierarchyWindow.SetExpandedRecursive(this.m_GameObject.GetInstanceID(), true); } this.CreateEditor(); this.m_EditMode = AvatarEditor.EditMode.Editing; this.m_SceneStates = new List<AvatarEditor.SceneStateCache>(); foreach (SceneView sceneView in SceneView.sceneViews) { this.m_SceneStates.Add(new AvatarEditor.SceneStateCache { state = new SceneView.SceneViewState(sceneView.m_SceneViewState), view = sceneView }); sceneView.m_SceneViewState.showFlares = false; sceneView.m_SceneViewState.showMaterialUpdate = false; sceneView.m_SceneViewState.showFog = false; sceneView.m_SceneViewState.showSkybox = false; sceneView.FrameSelected(); } }
private void CreateStateMachine() { if (avatarPreview == null || avatarPreview.Animator == null) return; if (controller == null) { controller = new AnimatorController(); controller.hideFlags = HideFlags.DontSave; controller.AddLayer("preview"); stateMachine = controller.layers[0].stateMachine; CreateParameters(); state = stateMachine.AddState("preview"); state.motion = previewedMotion; state.iKOnFeet = this.avatarPreview.IKOnFeet; state.hideFlags = HideFlags.DontSave; stateMachine.hideFlags = HideFlags.DontSave; AnimatorController.SetAnimatorController(avatarPreview.Animator, controller); controller.AppendOnAnimatorControllerDirtyCallback(this.ControllerDitry); controllerIsDitry = false; } if (AnimatorControllerExtension.GetEffectiveAnimatorController(avatarPreview.Animator) != this.controller) { AnimatorController.SetAnimatorController(avatarPreview.Animator, this.controller); } }