Ejemplo n.º 1
0
        public void Start()
        {
            m_Actor = gameObject.GetComponent <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.
                    };
                    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)
                    {
                        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);
                                Mat2D worldTransform = muzzle.WorldTransform;

                                AimSlice slice = m_AimLookup[i];

                                // Extract forward vector and position.
                                slice.dir = new Vec2D();
                                Vec2D.Normalize(slice.dir, new Vec2D(worldTransform[0], worldTransform[1]));
                                slice.point    = new Vec2D(worldTransform[4] * ActorAsset.NimaToUnityScale, worldTransform[5] * 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);
                                Mat2D worldTransform = muzzle.WorldTransform;

                                AimSlice slice = m_AimWalkingLookup[i];

                                // Extract forward vector and position.
                                slice.dir = new Vec2D();
                                Vec2D.Normalize(slice.dir, new Vec2D(worldTransform[0], worldTransform[1]));
                                slice.point           = new Vec2D(worldTransform[4] * ActorAsset.NimaToUnityScale, worldTransform[5] * ActorAsset.NimaToUnityScale);
                                m_AimWalkingLookup[i] = slice;
                            }
                        }
                    }
                }
            }
            m_IdleTime = 0.0f;
        }