// Start is called before the first frame update void Start() { audio = this.GetComponent <AudioSource>(); if (!player) { Debug.LogWarning("WARNING: You must set one enemy (the player character) for this script in the Inspector View!"); } levelManagerScript = GameObject.FindGameObjectWithTag("LevelManager").GetComponent <LevelManager>(); iaAnimationScript = transform.GetComponent <AiAnimation>(); currentState = enemyState.idle; }
private static AiNodeAnimationChannel FineNodeAnim(AiAnimation animation, string nodeName) { AiNodeAnimationChannel channel = null; for (int i = 0; i < animation.NodeAnimationChannelCount; i++) { var nodeAnim = animation.NodeAnimationChannels[i]; if (nodeAnim.NodeName == nodeName) { channel = nodeAnim; break; } } return(channel); }
private static void ReadNodeHeirarchy(float animationTime, AiNode node, AiAnimation animation, mat4 parentTransform, AllBoneInfos allBoneInfos) { string nodeName = node.Name; mat4 nodeTransform = node.Transform.ToMat4(); AiNodeAnimationChannel nodeAnim = FineNodeAnim(animation, nodeName); if (nodeAnim != null) { mat4 mat = mat4.identity(); // Interpolate scaling and generate scaling transformation matrix vec3 scaling = CalcInterpolatedScaling(animationTime, nodeAnim); mat4 scalingMat = glm.scale(mat, new vec3(scaling.X, scaling.Y, scaling.Z)); // Interpolate rotation and generate rotation transformation matrix Quaternion rotation = CalcInterpolatedRotation(animationTime, nodeAnim); mat4 rotationMat = new AiMatrix4x4(rotation.GetMatrix()).ToMat4(); // Interpolate translation and generate translation transformation matrix vec3 translation = CalcInterpolatedPosition(animationTime, nodeAnim); mat4 translationMat = glm.translate(mat4.identity(), new vec3(translation.X, translation.Y, translation.Z)); // Combine the above transformations nodeTransform = translationMat * rotationMat * scalingMat; } mat4 globalTransformation = parentTransform * nodeTransform; if (allBoneInfos.nameIndexDict.ContainsKey(nodeName)) { uint BoneIndex = allBoneInfos.nameIndexDict[nodeName]; allBoneInfos.boneInfos[BoneIndex].finalTransformation = globalTransformation * allBoneInfos.boneInfos[BoneIndex].bone.OffsetMatrix.ToMat4(); } for (int i = 0; i < node.ChildCount; i++) { ReadNodeHeirarchy(animationTime, node.Children[i], animation, globalTransformation, allBoneInfos); } }
static void CreateAsset() { AiAnimation asset = ScriptableObject.CreateInstance <AiAnimation>(); string path = AssetDatabase.GetAssetPath(Selection.activeObject); if (path == "") { path = "Assets"; } else if (Path.GetExtension(path) != "") { path = path.Replace(Path.GetFileName(AssetDatabase.GetAssetPath(Selection.activeObject)), ""); } string assetPathAndName = AssetDatabase.GenerateUniqueAssetPath(path + "/New Animation.asset"); AssetDatabase.CreateAsset(asset, assetPathAndName); AssetDatabase.SaveAssets(); AssetDatabase.Refresh(); EditorUtility.FocusProjectWindow(); Selection.activeObject = asset; }
public void PlayAnimation(string id) { currAnim = GetAnimationById(id); animTimer = 0; playingAnim = true; }