Esempio n. 1
0
    public void AIPlayAnimation(AIAnimation.Animation anim)
    {
        if (anim == AIAnimation.Animation.none)
        {
            return;
        }

        AIAnimation packet = new AIAnimation();

        packet.id = localID;

        packet.anim = anim;
        socket.Emit("ai_animation", JsonUtility.ToJson(packet));
    }
Esempio n. 2
0
        public void PlayAnimationNode(AIAnimation _animation, float _speed, bool inheritBlendZeroReset = false)
        {
            float zeroReset = 0;

            if (inheritBlendZeroReset)
            {
                zeroReset = blendZeroReset;
            }
            else
            {
                //we need to calculate back what the shader is doing so we can start at time 0
                zeroReset = CalculateZeroReset(_animation.length, _speed);
            }

            //Debug.Log("Play" + meshRenderers[0].transform.name);

            int i = 0;

            foreach (MeshRenderer renderer in meshRenderers)
            {
                MaterialPropertyBlock propertyBlock = new MaterialPropertyBlock();
                renderer.GetPropertyBlock(propertyBlock);

                //animation duration
                propertyBlock.SetFloat("_AnimationDuration", _animation.length);

                //animation texture
                propertyBlock.SetTexture("_AnimationTexture", _animation.animationTexture);

                //animation speed
                propertyBlock.SetFloat("_AnimationSpeed", _speed);

                //max magnitude of this renderer
                propertyBlock.SetFloat("_MaxMagnitude", _animation.maxMagnitudes[i]);

                //current animation width
                propertyBlock.SetFloat("_AnimationWidth", _animation.animationTexture.width);

                //reset time
                propertyBlock.SetFloat("_AnimationZeroReset", zeroReset);

                propertyBlock.SetFloat("_LerpSpeed", 0);

                renderer.SetPropertyBlock(propertyBlock);

                i++;
            }

            animationZeroReset = zeroReset;
        }
Esempio n. 3
0
    private void EndBake()
    {
        StopBake();
        Debug.Log("Writing to Texture...");

        string texPath = saveDirectory + "/" + animationForSave[currentIndex] + ".png";

        File.WriteAllBytes(texPath, texture.EncodeToPNG());


        AIAnimation animation = ScriptableObject.CreateInstance <AIAnimation>();

        if (!combined)
        {
            animation.maxMagnitudes = maxMagnitudes;
        }
        else
        {
            animation.maxMagnitudes = new float[] { maxCombinedMagnitude };
        }
        animation.length = clipLenght;

        if (File.Exists(texPath))
        {
            byte[] texData;
            texData = File.ReadAllBytes(texPath);

            Texture2D tex = new Texture2D(2, 2);
            tex.LoadImage(texData);
            animation.animationTexture = tex;
        }
        //   animation.startMeshes = firstMeshes;

        string absolutePath = saveDirectory + "/" + animationForSave[currentIndex] + ".asset";
        string relativePath = Application.dataPath;

        if (absolutePath.StartsWith(Application.dataPath))
        {
            relativePath = "Assets" + absolutePath.Substring(Application.dataPath.Length);
        }

        AssetDatabase.CreateAsset(animation, relativePath);

        AssetDatabase.SaveAssets();

        Debug.Log("Finished Writing");
    }
Esempio n. 4
0
        protected override void DrawWindowContents(int _id)
        {
            GUIStyle style = GUI.skin.label;

            style.fontSize = graph.fontSize;



            GUILayout.Space(Mathf.Max(0, graph.controller.zoom));
            GUILayout.BeginHorizontal();
            GUILayout.Label("Animation: ", style);
            animation = (AIAnimation)EditorGUILayout.ObjectField(animation, typeof(AIAnimation), false, GUILayout.ExpandHeight(true), GUILayout.MaxHeight(Mathf.Max(20, graph.controller.zoom)));

            GUILayout.EndHorizontal();

            base.DrawWindowContents(_id);
        }
Esempio n. 5
0
    public void OnAIPlayAnimation(SocketIOEvent obj)
    {
        AIAnimation packet = JsonUtility.FromJson <AIAnimation>(obj.data);

        if (packet.anim == AIAnimation.Animation.none)
        {
            return;
        }

        if (players.ContainsKey(packet.id))
        {
            EnemyAI ai = players[packet.id].GetComponentInChildren <EnemyAI>();
            if (ai == null)
            {
                return;
            }

            switch (packet.anim)
            {
            case AIAnimation.Animation.idle:
                ai.PlayIdleAnim();
                break;

            case AIAnimation.Animation.walk:
                ai.PlayWalkAnim();
                break;

            case AIAnimation.Animation.run:
                ai.PlayRunAnim();
                break;

            case AIAnimation.Animation.aim:
                ai.PlayAimAnim();
                break;

            case AIAnimation.Animation.shoot:
                ai.PlayShootAnim();
                break;

            case AIAnimation.Animation.die:
                ai.PlayDeathAnim();
                break;
            }
        }
    }
Esempio n. 6
0
        public void PlayTransition(Transition _transition, AIAnimation _endAnimation, float _endSpeed)
        {
            //we need to calculate back what the shader is doing so we can start at time 0
            blendZeroReset = CalculateZeroReset(_endAnimation.length, _endSpeed);
            float lerpZeroReset = CalculateZeroReset(_transition.transitionTime, 1);


            int i = 0;

            foreach (MeshRenderer renderer in meshRenderers)
            {
                //    renderer.GetComponent<MeshFilter>().sharedMesh = currentAnimation.startMeshes[i];

                MaterialPropertyBlock propertyBlock = new MaterialPropertyBlock();
                renderer.GetPropertyBlock(propertyBlock);

                //animation texture
                propertyBlock.SetTexture("_BlendAnimationTexture", _endAnimation.animationTexture);

                //max magnitude of this renderer
                propertyBlock.SetFloat("_BlendMaxMagnitude", _endAnimation.maxMagnitudes[i]);

                //current animation width
                propertyBlock.SetFloat("_BlendAnimationWidth", _endAnimation.animationTexture.width);

                //animation speed
                propertyBlock.SetFloat("_BlendAnimationSpeed", _endSpeed);

                //reset time
                propertyBlock.SetFloat("_BlendZeroReset", blendZeroReset);

                //animation duration
                propertyBlock.SetFloat("_BlendDuration", _endAnimation.length);

                //reset time
                propertyBlock.SetFloat("_LerpZeroReset", lerpZeroReset);

                //animation duration
                propertyBlock.SetFloat("_LerpSpeed", _transition.transitionTime);

                renderer.SetPropertyBlock(propertyBlock);

                i++;
            }
        }
Esempio n. 7
0
	public IEnumerator Start () {
		waypointPosition = transform.position;
		command = Command.Stay;
		controller = GetComponent (typeof(CharacterController)) as CharacterController;
		Object anim = GetComponent (typeof(AIAnimation));
		animator = anim != null ? anim as AIAnimation : null;
		seeker = GetComponent (typeof(Seeker)) as Seeker;
		
		StartCoroutine (Patrol());
		yield return new WaitForSeconds (Random.value*0.5F);
		
		if (continousTargetSearch) {
			StartCoroutine (SearchPlayer());
		}
		
		while (true) {
			FindPoint (curpoint);
			yield return new WaitForSeconds (SearchWaypointFrequency);
		}
	}
Esempio n. 8
0
    public IEnumerator Start()
    {
        waypointPosition = transform.position;
        command          = Command.Stay;
        controller       = GetComponent(typeof(CharacterController)) as CharacterController;
        Object anim = GetComponent(typeof(AIAnimation));

        animator = anim != null ? anim as AIAnimation : null;
        seeker   = GetComponent(typeof(Seeker)) as Seeker;

        StartCoroutine(Patrol());
        yield return(new WaitForSeconds(Random.value * 0.5F));

        if (continousTargetSearch)
        {
            StartCoroutine(SearchPlayer());
        }

        while (true)
        {
            FindPoint(curpoint);
            yield return(new WaitForSeconds(SearchWaypointFrequency));
        }
    }