Exemplo n.º 1
0
        public override void Initialize(ActorBaseComponent actorBaseComponent)
        {
            base.Initialize(actorBaseComponent);

            ActorComponent actorComponent = actorBaseComponent as ActorComponent;

            m_SortingOrderOffset = actorComponent.SortingOrder;

            ActorImage imageNode = m_ActorNode as ActorImage;

            // Attach the skinned bone nodes to the bones of the skinned renderer.
            if (imageNode.IsSkinned)
            {
                SkinnedMeshRenderer skinnedRenderer = gameObject.GetComponent <SkinnedMeshRenderer>();

                Transform[] transforms = new Transform[imageNode.ConnectedBoneCount + 1];
                transforms[0] = actorComponent.DefaultBone.transform;
                int idx = 1;
                foreach (ActorImage.BoneConnection bc in imageNode.BoneConnections)
                {
                    ActorNodeComponent boneComponent = actorComponent.Nodes[bc.m_BoneIdx];
                    transforms[idx] = boneComponent.gameObject.transform;
                    idx++;
                }
                skinnedRenderer.bones = transforms;
            }
        }
Exemplo n.º 2
0
 private static void UpdateGameObjectsFor(ActorAsset actorAsset)
 {
     Object[] list = Resources.FindObjectsOfTypeAll(typeof(GameObject));
     foreach (Object obj in list)
     {
         GameObject     go    = obj as GameObject;
         ActorComponent actor = go.GetComponent <ActorComponent>();
         if (actor != null && actor.Asset == actorAsset)
         {
             Debug.Log("FOUND ACTOR WITH UPDATED ASSET");
             // We found an actor using the asset that got updated. Let's update the game object.
             actor.InitializeFromAsset(actorAsset);
         }
     }
 }
Exemplo n.º 3
0
        public void Start()
        {
            m_Actor = gameObject.GetComponent <ActorComponent>();
            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);
                                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], worldTransform[5]);
                                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);
                                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], worldTransform[5]);
                                m_AimWalkingLookup[i] = slice;
                            }
                        }
                    }
                }
            }
            m_IdleTime = 0.0f;
        }
        void Start()
        {
            m_Animator = GetComponent <Animator>();
            m_Actor    = gameObject.GetComponent <ActorComponent>();
            if (m_Actor != null)
            {
                if (m_Actor.ActorInstance != null)
                {
                    m_Aim = m_Actor.ActorInstance.GetAnimation("Aim2");
                    Nima.Animation.ActorAnimation walk       = m_Actor.ActorInstance.GetAnimation("Walk");
                    Nima.Animation.ActorAnimation walkToIdle = m_Actor.ActorInstance.GetAnimation("WalkToIdle");


                    // 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);
                                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], worldTransform[5]);
                                m_AimLookup[i] = slice;
                            }
                        }
                        if (walk != null)
                        {
                            walk.Apply(0.0f, m_Actor.ActorInstance, 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);
                                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], worldTransform[5]);
                                m_AimWalkingLookup[i] = slice;
                            }
                        }

                        if (walkToIdle != null)
                        {
                            walkToIdle.Apply(walkToIdle.Duration, m_Actor.ActorInstance, 1.0f);
                        }
                    }
                }
            }
        }