Exemplo n.º 1
0
        public override ActorComponent MakeInstance(Actor resetActor)
        {
            CustomBooleanProperty instanceProperty = new CustomBooleanProperty();

            instanceProperty.Copy(this, resetActor);
            return(instanceProperty);
        }
Exemplo n.º 2
0
 public void AddCustomBooleanProperty(CustomBooleanProperty property)
 {
     if (m_CustomBooleanProperties == null)
     {
         m_CustomBooleanProperties = new List <CustomBooleanProperty>();
     }
     m_CustomBooleanProperties.Add(property);
 }
Exemplo n.º 3
0
 public static CustomBooleanProperty Read(Actor actor, BinaryReader reader, CustomBooleanProperty property = null)
 {
     if (property == null)
     {
         property = new CustomBooleanProperty();
     }
     ActorComponent.Read(actor, reader, property);
     property.Value = reader.ReadByte() == 1;
     return(property);
 }
Exemplo n.º 4
0
        private void ReadComponentsBlock(BlockReader block)
        {
            int componentCount = block.ReadUInt16();

            m_Components    = new ActorComponent[componentCount + 1];
            m_Components[0] = m_Root;

            // Guaranteed from the exporter to be in index order.
            BlockReader nodeBlock = null;

            int componentIndex = 1;

            m_NodeCount = 1;
            while ((nodeBlock = block.ReadNextBlock()) != null)
            {
                ActorComponent component = null;
                if (Enum.IsDefined(typeof(BlockTypes), nodeBlock.BlockType))
                {
                    BlockTypes type = (BlockTypes)nodeBlock.BlockType;
                    switch (type)
                    {
                    case BlockTypes.ActorNode:
                        component = ActorNode.Read(this, nodeBlock);
                        break;

                    case BlockTypes.ActorBone:
                        component = ActorBone.Read(this, nodeBlock);
                        break;

                    case BlockTypes.ActorRootBone:
                        component = ActorRootBone.Read(this, nodeBlock);
                        break;

                    case BlockTypes.ActorImage:
                        m_ImageNodeCount++;
                        component = ActorImage.Read(this, nodeBlock, makeImageNode());
                        if ((component as ActorImage).TextureIndex > m_MaxTextureIndex)
                        {
                            m_MaxTextureIndex = (component as ActorImage).TextureIndex;
                        }
                        break;

                    case BlockTypes.ActorIKTarget:
                        component = ActorIKTarget.Read(this, nodeBlock);
                        break;

                    case BlockTypes.ActorEvent:
                        component = ActorEvent.Read(this, nodeBlock);
                        break;

                    case BlockTypes.CustomIntProperty:
                        component = CustomIntProperty.Read(this, nodeBlock);
                        break;

                    case BlockTypes.CustomFloatProperty:
                        component = CustomFloatProperty.Read(this, nodeBlock);
                        break;

                    case BlockTypes.CustomStringProperty:
                        component = CustomStringProperty.Read(this, nodeBlock);
                        break;

                    case BlockTypes.CustomBooleanProperty:
                        component = CustomBooleanProperty.Read(this, nodeBlock);
                        break;

                    case BlockTypes.ActorColliderRectangle:
                        component = ActorColliderRectangle.Read(this, nodeBlock);
                        break;

                    case BlockTypes.ActorColliderTriangle:
                        component = ActorColliderTriangle.Read(this, nodeBlock);
                        break;

                    case BlockTypes.ActorColliderCircle:
                        component = ActorColliderCircle.Read(this, nodeBlock);
                        break;

                    case BlockTypes.ActorColliderPolygon:
                        component = ActorColliderPolygon.Read(this, nodeBlock);
                        break;

                    case BlockTypes.ActorColliderLine:
                        component = ActorColliderLine.Read(this, nodeBlock);
                        break;

                    case BlockTypes.ActorNodeSolo:
                        component = ActorNodeSolo.Read(this, nodeBlock);
                        break;

                    case BlockTypes.ActorJellyBone:
                        component = ActorJellyBone.Read(this, nodeBlock);
                        break;

                    case BlockTypes.JellyComponent:
                        component = JellyComponent.Read(this, nodeBlock);
                        break;

                    case BlockTypes.ActorIKConstraint:
                        component = ActorIKConstraint.Read(this, nodeBlock);
                        break;

                    case BlockTypes.ActorDistanceConstraint:
                        component = ActorDistanceConstraint.Read(this, nodeBlock);
                        break;

                    case BlockTypes.ActorTranslationConstraint:
                        component = ActorTranslationConstraint.Read(this, nodeBlock);
                        break;

                    case BlockTypes.ActorScaleConstraint:
                        component = ActorScaleConstraint.Read(this, nodeBlock);
                        break;

                    case BlockTypes.ActorRotationConstraint:
                        component = ActorRotationConstraint.Read(this, nodeBlock);
                        break;

                    case BlockTypes.ActorTransformConstraint:
                        component = ActorTransformConstraint.Read(this, nodeBlock);
                        break;
                    }
                }
                if (component is ActorNode)
                {
                    m_NodeCount++;
                }

                m_Components[componentIndex] = component;
                if (component != null)
                {
                    component.Idx = (ushort)(componentIndex);
                }
                componentIndex++;
            }

            m_ImageNodes = new ActorImage[m_ImageNodeCount];
            m_Nodes      = new ActorNode[m_NodeCount];
            m_Nodes[0]   = m_Root;

            // Resolve nodes.
            int imgIdx = 0;
            int anIdx  = 0;

            ActorComponent[] components = m_Components;
            for (int i = 1; i <= componentCount; i++)
            {
                ActorComponent c = components[i];
                // Nodes can be null if we read from a file version that contained nodes that we don't interpret in this runtime.
                if (c != null)
                {
                    c.ResolveComponentIndices(components);
                }

                ActorImage ain = c as ActorImage;
                if (ain != null)
                {
                    m_ImageNodes[imgIdx++] = ain;
                }

                ActorNode an = c as ActorNode;
                if (an != null)
                {
                    m_Nodes[anIdx++] = an;
                }
            }

            for (int i = 1; i <= componentCount; i++)
            {
                ActorComponent c = components[i];
                if (c != null)
                {
                    c.CompleteResolve();
                }
            }

            SortDependencies();
        }
Exemplo n.º 5
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.º 6
0
 public void Copy(CustomBooleanProperty prop, Actor resetActor)
 {
     base.Copy(prop, resetActor);
     m_Value = prop.m_Value;
 }