Exemplo n.º 1
0
 private void loopPlayAnim(Nima.Animation.ActorAnimation anim, ref float time, float speed = 1f)
 {
     if (anim == null)
     {
         return;
     }
     time = (time + Time.deltaTime * speed) % anim.Duration;
     anim.Apply(time, m_Actor.ActorInstance, 1.0f);
 }
Exemplo n.º 2
0
 private bool playUntilEndAnim(Nima.Animation.ActorAnimation anim, ref float time, float speed = 1f)
 {
     if (anim == null)
     {
         return(false);
     }
     time = (time + Time.deltaTime * speed);
     if (time >= anim.Duration - .05f)
     {
         time = anim.Duration - .05f;
         anim.Apply(time, m_Actor.ActorInstance, 1.0f);
         return(true);
     }
     if (time <= 0)
     {
         time = 0;
     }
     anim.Apply(time, m_Actor.ActorInstance, 1.0f);
     return(false);
 }
Exemplo n.º 3
0
    public void Update()
    {
        if (m_Actor == null)
        {
            return;
        }

        // Advance idle animations first.
        loopPlayAnim(title, ref title_time, 1);
        start.Apply(0, m_Actor.ActorInstance, 1.0f);
        if (Input.GetKeyDown("z"))
        {
            starting = true;
        }
        if (starting)
        {
            if (playUntilEndAnim(start, ref start_time))
            {
                SceneManager.LoadScene("SampleScene");
            }
            titleSong.volume = 1 - start_time;
        }
    }
Exemplo n.º 4
0
    public void Start()
    {
        m_Actor = gameObject.GetComponent <Nima.Unity.ActorBaseComponent>();
        if (m_Actor != null)
        {
            // Get a game object from the actor, use this to mount items or query for other components.
            // GameObject headColliderGameObject = m_Actor.GetActorGameObject("HeadCollider");
            // if(headColliderGameObject != null)
            // {
            //  Collider2D collider = headColliderGameObject.GetComponent<Collider2D>();
            //  if(collider != null)
            //  {
            //      // Set it to a trigger, or do something else with it...
            //      // collider.isTrigger = true;
            //  }
            // }
            if (m_Actor.ActorInstance != null)
            {
                m_Idle       = m_Actor.ActorInstance.GetAnimation("Idle");
                m_Aim        = m_Actor.ActorInstance.GetAnimation("Aim2");
                m_Walk       = m_Actor.ActorInstance.GetAnimationInstance("Walk");
                m_Run        = m_Actor.ActorInstance.GetAnimation("Run");
                m_WalkToIdle = m_Actor.ActorInstance.GetAnimation("WalkToIdle");

                // We made walk an animation instance so it has it's own sense of time which lets it do things like track events.
                m_Walk.AnimationEvent += delegate(object animationInstance, Nima.Animation.AnimationEventArgs args)
                {
                    // Event triggered from animation.
                };
                Nima.ActorNode characterNode = m_Actor.ActorInstance.GetNode("Character");
                if (characterNode != null)
                {
                    m_GroundSpeedProperty = characterNode.GetCustomFloatProperty("GroundSpeed");
                    m_IsRunningProperty   = characterNode.GetCustomBooleanProperty("IsRunning");
                }
                // Calculate aim slices.
                if (m_Aim != null)
                {
                    Nima.ActorNode muzzle = m_Actor.ActorInstance.GetNode("Muzzle");
                    if (muzzle != null)
                    {
                        for (int i = 0; i < AimSliceCount; i++)
                        {
                            float position = i / (float)(AimSliceCount - 1) * m_Aim.Duration;
                            m_Aim.Apply(position, m_Actor.ActorInstance, 1.0f);
                            m_Actor.ActorInstance.Advance(0.0f);
                            Nima.Math2D.Mat2D worldTransform = muzzle.WorldTransform;

                            AimSlice slice = m_AimLookup[i];

                            // Extract forward vector and position.
                            slice.dir = new Nima.Math2D.Vec2D();
                            Nima.Math2D.Vec2D.Normalize(slice.dir, new Nima.Math2D.Vec2D(worldTransform[0], worldTransform[1]));
                            slice.point = new Nima.Math2D.Vec2D(worldTransform[4] * Nima.Unity.ActorAsset.NimaToUnityScale,
                                                                worldTransform[5] * Nima.Unity.ActorAsset.NimaToUnityScale);
                            m_AimLookup[i] = slice;
                        }
                    }
                    if (m_Walk != null)
                    {
                        m_Walk.Time = 0.0f;
                        m_Walk.Apply(1.0f);

                        for (int i = 0; i < AimSliceCount; i++)
                        {
                            float position = i / (float)(AimSliceCount - 1) * m_Aim.Duration;
                            m_Aim.Apply(position, m_Actor.ActorInstance, 1.0f);
                            m_Actor.ActorInstance.Advance(0.0f);
                            Nima.Math2D.Mat2D worldTransform = muzzle.WorldTransform;

                            AimSlice slice = m_AimWalkingLookup[i];

                            // Extract forward vector and position.
                            slice.dir = new Nima.Math2D.Vec2D();
                            Nima.Math2D.Vec2D.Normalize(slice.dir, new Nima.Math2D.Vec2D(worldTransform[0], worldTransform[1]));
                            slice.point = new Nima.Math2D.Vec2D(worldTransform[4] * Nima.Unity.ActorAsset.NimaToUnityScale,
                                                                worldTransform[5] * Nima.Unity.ActorAsset.NimaToUnityScale);
                            m_AimWalkingLookup[i] = slice;
                        }
                    }
                }
            }
        }
        m_IdleTime = 0.0f;
    }
Exemplo n.º 5
0
    public void Update()
    {
        if (m_Actor == null)
        {
            return;
        }

        if (m_IsRunningProperty != null)
        {
            // Just an example of how to detect if the character is running from the animated properties (not really necessary here but shows how you can use custom properties).
            // Debug.Log("RUNNING " + m_IsRunningProperty.Value);
        }
        float elapsedSeconds = Time.deltaTime;

        Nima.Actor actorInstance = m_Actor.ActorInstance;

        float scaleX = 1.0f;        //ActorAsset.NimaToUnityScale;
        // Find cursor position in world space.
        Ray     ray = Camera.main.ScreenPointToRay(Input.mousePosition);
        Vector3 actorLocalCursor = m_Actor.gameObject.transform.InverseTransformPoint(ray.origin);

        if (actorLocalCursor[0] < 0.0f)
        {
            scaleX *= -1.0f;
            actorLocalCursor[0] *= -1.0f;
        }

        actorInstance.Root.ScaleX = scaleX;

        // Advance idle animation first.
        if (m_Idle != null)
        {
            m_IdleTime = (m_IdleTime + elapsedSeconds) % m_Idle.Duration;
            m_Idle.Apply(m_IdleTime, m_Actor.ActorInstance, 1.0f);
        }

        // Update input.
        if (m_HorizontalSpeed != -1.0f && (Input.GetKeyDown(KeyCode.A) || Input.GetKeyDown(KeyCode.LeftArrow)))
        {
            m_HorizontalSpeed = -1.0f;
        }
        else if (m_HorizontalSpeed == -1.0f && (Input.GetKeyUp(KeyCode.A) || Input.GetKeyUp(KeyCode.LeftArrow)))
        {
            m_HorizontalSpeed = 0.0f;
        }
        if (m_HorizontalSpeed != 1.0f && (Input.GetKeyDown(KeyCode.D) || Input.GetKeyDown(KeyCode.RightArrow)))
        {
            m_HorizontalSpeed = 1.0f;
        }
        else if (m_HorizontalSpeed == 1.0f && (Input.GetKeyUp(KeyCode.D) || Input.GetKeyUp(KeyCode.RightArrow)))
        {
            m_HorizontalSpeed = 0.0f;
        }
        if (!m_IsRunning && (Input.GetKeyDown(KeyCode.LeftShift) || Input.GetKeyDown(KeyCode.RightShift)))
        {
            m_IsRunning = true;
        }
        else if (m_IsRunning && (Input.GetKeyUp(KeyCode.LeftShift) || Input.GetKeyUp(KeyCode.RightShift)))
        {
            m_IsRunning = false;
        }

        if (m_HorizontalSpeed != 0.0f)
        {
            if (m_IsRunning)
            {
                if (m_WalkMix > 0.0f)
                {
                    m_WalkMix = Math.Max(0.0f, m_WalkMix - elapsedSeconds * MixSpeed);
                }
                if (m_RunMix < 1.0f)
                {
                    m_RunMix = Math.Min(1.0f, m_RunMix + elapsedSeconds * MixSpeed);
                }
            }
            else
            {
                if (m_WalkMix < 1.0f)
                {
                    m_WalkMix = Math.Min(1.0f, m_WalkMix + elapsedSeconds * MixSpeed);
                }
                if (m_RunMix > 0.0f)
                {
                    m_RunMix = Math.Max(0.0f, m_RunMix - elapsedSeconds * MixSpeed);
                }
            }

            m_WalkToIdleTime = 0.0f;
        }
        else
        {
            if (m_WalkMix > 0.0f)
            {
                m_WalkMix = Math.Max(0.0f, m_WalkMix - elapsedSeconds * MixSpeed);
            }
            if (m_RunMix > 0.0f)
            {
                m_RunMix = Math.Max(0.0f, m_RunMix - elapsedSeconds * MixSpeed);
            }
        }

        float moveSpeed = m_IsRunning ? 11.0f : 6.0f;
//			m_Actor.gameObject.transform.
//			actorInstance.Root.X += m_HorizontalSpeed * elapsedSeconds * moveSpeed;
        float speedModifier = 1.0f;

        if (m_GroundSpeedProperty != null)
        {
            speedModifier = (m_IsRunning ? 1.0f - m_GroundSpeedProperty.Value : m_GroundSpeedProperty.Value) * 0.5f + 0.5f;
        }
        m_Actor.gameObject.transform.Translate(new Vector3(1.0f, 0.0f, 0.0f) * m_HorizontalSpeed * speedModifier * elapsedSeconds * moveSpeed);
        if (m_Walk != null && m_Run != null)
        {
            if (m_HorizontalSpeed == 0.0f && m_WalkMix == 0.0f && m_RunMix == 0.0f)
            {
                m_Walk.Time = 0.0f;
                //m_WalkTime = 0.0f;
                m_RunTime = 0.0f;
            }
            else
            {
                //m_WalkTime = m_WalkTime + elapsedSeconds * 0.9f * (m_HorizontalSpeed > 0 ? 1.0f : -1.0f) * (scaleX < 0.0 ? -1.0f : 1.0f);
                m_Walk.Advance(elapsedSeconds * 0.9f * (m_HorizontalSpeed > 0 ? 1.0f : -1.0f) * (scaleX < 0.0 ? -1.0f : 1.0f));
                // Sync up the run and walk times.
                //m_WalkTime %= m_Walk.Duration;

                /*if(m_WalkTime < 0.0f)
                 * {
                 *      m_WalkTime += m_Walk.Duration;
                 * }*/
                m_RunTime = (m_Walk.Time - m_Walk.MinTime) / m_Walk.MaxTime * m_Run.Duration;
            }

            if (m_WalkMix != 0.0f)
            {
                m_Walk.Apply(m_WalkMix);
            }
            if (m_RunMix != 0.0f)
            {
                m_Run.Apply(m_RunTime, actorInstance, m_RunMix);
            }


            if (m_WalkToIdle != null && m_HorizontalSpeed == 0.0f && m_WalkToIdleTime < m_WalkToIdle.Duration)
            {
                m_WalkToIdleTime += elapsedSeconds;
                m_WalkToIdle.Apply(m_WalkToIdleTime, actorInstance, Math.Min(1.0f, m_WalkToIdleTime / m_WalkToIdle.Duration));
                //m_RunMix = m_WalkMix = 0.0;
            }
        }

        if (m_Aim != null)
        {
            // Figure out best aim position.
            Nima.Math2D.Vec2D actorTarget = new Nima.Math2D.Vec2D(actorLocalCursor[0], actorLocalCursor[1]);

            // Now actorTarget is in Nima root space.
            float      maxDot    = -1.0f;
            int        bestIndex = 0;
            AimSlice[] lookup    = m_HorizontalSpeed == 0.0f ? m_AimLookup : m_AimWalkingLookup;

            Nima.Math2D.Vec2D targetDir = new Nima.Math2D.Vec2D();
            for (int i = 0; i < AimSliceCount; i++)
            {
                AimSlice aim = lookup[i];


                Nima.Math2D.Vec2D.Subtract(targetDir, actorTarget, aim.point);
                Nima.Math2D.Vec2D.Normalize(targetDir, targetDir);
                float d = Nima.Math2D.Vec2D.Dot(targetDir, aim.dir);
                if (d > maxDot)
                {
                    maxDot    = d;
                    bestIndex = i;
                }
            }
            float targetAimTime = bestIndex / (float)(AimSliceCount - 1) * m_Aim.Duration;

            m_AimAnimationTime += (targetAimTime - m_AimAnimationTime) * Math.Min(1.0f, elapsedSeconds * 10.0f);
            m_Aim.Apply(m_AimAnimationTime, m_Actor.ActorInstance, 1.0f);
        }
    }
Exemplo n.º 6
0
 public void Apply(float mix)
 {
     m_Animation.Apply(m_Time, m_Actor, mix);
 }
Exemplo n.º 7
0
    public void Update()
    {
        if (m_Actor == null)
        {
            return;
        }
        if (fade_time > targetFade)
        {
            fade_time -= Time.deltaTime * fadeSpeed;
        }
        if (fade_time < targetFade)
        {
            fade_time += Time.deltaTime * fadeSpeed;
        }
        fade.Apply(fade_time, m_Actor.ActorInstance, 1.0f);
        if (show_z_time > targetZ)
        {
            show_z_time -= Time.deltaTime * zSpeed;
        }
        if (show_z_time < targetZ)
        {
            show_z_time += Time.deltaTime * zSpeed;
        }
        show_z.Apply(show_z_time, m_Actor.ActorInstance, 1.0f);
        if (show_x_time > targetX)
        {
            show_x_time -= Time.deltaTime * xSpeed;
        }
        if (show_x_time < targetX)
        {
            show_x_time += Time.deltaTime * xSpeed;
        }
        show_x.Apply(show_x_time, m_Actor.ActorInstance, 1.0f);

        // Advance idle animations first.
        loopPlayAnim(flame_flicker2, ref flame_flicker2_time, flameSpeed);
        loopPlayAnim(smoke_flicker, ref smoke_flicker_time, smokeSpeed);

        if (clawsExtended)
        {
            if (playUntilEndAnim(claws_contract, ref claws_contract_time))
            {
                // if claws have finished extending, play the claw idle animation
                loopPlayAnim(claws_idle, ref claws_idle_time);
                // only play sparking if claws have finished extending
                if (clawsSparking)
                {
                    loopPlayAnim(claws_spark, ref claws_spark_time);
                }
                else
                {
                    claws_spark.Apply(0, m_Actor.ActorInstance, 1.0f);
                }
            }
            else
            {
                claws_idle_time = 0;
            }
        }
        else
        {
            playUntilEndAnim(claws_contract, ref claws_contract_time, -1f);
        }

        if (armsExtended)
        {
            if (playUntilEndAnim(arms_contract, ref arms_contract_time))
            {
                // if arms have finished extending, play the arms idle animation
                loopPlayAnim(arms_idle, ref arms_idle_time);
                // only play firing if arms have finished extending
                if (armsFiring)
                {
                    loopPlayAnim(arms_fire, ref arms_fire_time);
                }
                else
                {
                    arms_fire.Apply(0, m_Actor.ActorInstance, 1.0f);
                }
            }
            else
            {
                arms_idle_time = 0;
            }
        }
        else
        {
            playUntilEndAnim(arms_contract, ref arms_contract_time, -1f);
        }

        smoke_stability.Apply(smokeStability, m_Actor.ActorInstance, 1.0f);
        flame_size.Apply(flameSize, m_Actor.ActorInstance, 1.0f);
        smoke_opacity.Apply(smokeOpacity, m_Actor.ActorInstance, 1.0f);
        flame_opacity.Apply(flameOpacity, m_Actor.ActorInstance, 1.0f);
    }