コード例 #1
0
        public static async void HandleAsync(this ActorComponent self)
        {
            ActorMessageDispatherComponent actorMessageDispatherComponent = Game.Scene.GetComponent <ActorMessageDispatherComponent>();

            while (true)
            {
                if (self.IsDisposed)
                {
                    return;
                }
                try
                {
                    ActorMessageInfo info = await self.GetAsync();

                    // 返回null表示actor已经删除,协程要终止
                    if (info.Message == null)
                    {
                        return;
                    }

                    // 根据这个actor的类型分发给相应的ActorHandler处理
                    await actorMessageDispatherComponent.ActorTypeHandle(self.ActorType, (Entity)self.Parent, info);
                }
                catch (Exception e)
                {
                    Log.Error(e);
                }
            }
        }
コード例 #2
0
        public override void ComponentAwake()
        {
            actor      = GetRequiredComponent <ActorComponent>();
            despawner  = GetRequiredComponent <DespawnComponent>();
            collider2d = GetRequiredComponent <Collider2D>();
            rigidBody  = GetRequiredComponent <Rigidbody2D>();


            if (!UnityUtils.Exists(player))
            {
                throw new UnityException($"{gameObject.name} needs a player object dragged onto its NPCBrain");
            }

            playerActor = GetRequiredComponent <ActorComponent>(player);


            if (!UnityUtils.Exists(onIdleStateBehavior))
            {
                throw new UnityException("Idle State Behavior is null.  Please drag one onto the inspector.");
            }

            if (!UnityUtils.Exists(onActiveStateBehavior))
            {
                throw new UnityException("Active State Behavior is null.  Please drag one onto the inspector.");
            }


            base.ComponentAwake();
        }
コード例 #3
0
        public override void ComponentAwake()
        {
            playerActor    = GetRequiredComponent <ActorComponent>(GetRequiredObject("Player"));
            healthBarImage = GetRequiredComponent <Image>(GetRequiredChild("Health"));

            base.ComponentAwake();
        }
コード例 #4
0
        public override void ApplyInterpolation(ActorComponent component, float time, KeyFrame toFrame, float mix)
        {
            ActorImage imageNode = component as ActorImage;

            float[] wr = imageNode.AnimationDeformedVertices;
            float[] to = (toFrame as KeyFrameVertexDeform).m_Vertices;
            int     l  = m_Vertices.Length;

            float f  = (time - m_Time) / (toFrame.Time - m_Time);
            float fi = 1.0f - f;

            if (mix == 1.0f)
            {
                for (int i = 0; i < l; i++)
                {
                    wr[i] = m_Vertices[i] * fi + to[i] * f;
                }
            }
            else
            {
                float mixi = 1.0f - mix;
                for (int i = 0; i < l; i++)
                {
                    float v = m_Vertices[i] * fi + to[i] * f;

                    wr[i] = wr[i] * mixi + v * mix;
                }
            }

            imageNode.IsVertexDeformDirty = true;
        }
コード例 #5
0
        private static async void HandleAsync(this ActorComponent self)
        {
            while (true)
            {
                if (self.IsDisposed)
                {
                    return;
                }
                try
                {
                    ActorMessageInfo info = await self.GetAsync();

                    // 返回null表示actor已经删除,协程要终止
                    if (info == null)
                    {
                        return;
                    }
                    await self.entityActorHandler.Handle(info.Session, (Entity)self.Parent, info.RpcId, info.Message);
                }
                catch (Exception e)
                {
                    Log.Error(e.ToString());
                }
            }
        }
コード例 #6
0
        private void _createBullet(IEntity entity)
        {
            var viewComponent    = entity.GetComponent <ViewComponent>();
            var go               = viewComponent.View.gameObject;
            var startPosition    = go.transform.position + (go.transform.up * 0.25f);
            var bullet           = _pool.CreateEntity();
            var enemyMask        = 1 << LayerMask.NameToLayer("Enemy");
            var destructibleMask = 1 << LayerMask.NameToLayer("Destructible");
            var finalMask        = enemyMask | destructibleMask;
            var bulletComponent  = new BulletComponent()
            {
                startPosition = startPosition,
                rotation      = _addDispersion(go.transform.rotation),
                elapsedTime   = 0,
                lifeTime      = .8f,
                collisionMask = finalMask
            };
            var actorComponent = new ActorComponent()
            {
                damage = 5
            };

            bullet.AddComponent(bulletComponent);
            bullet.AddComponent(actorComponent);
            bullet.AddComponent(new ViewComponent());
        }
コード例 #7
0
ファイル: MainGame.cs プロジェクト: DonkerNet/pong
        // Create all the components that should be used by this game
        private void CreateComponents()
        {
            _menuComponent = new MenuComponent(this);
            Components.Add(_menuComponent);

            _backgroundComponent = new BackgroundComponent(this);
            Components.Add(_backgroundComponent);

            _actorComponent = new ActorComponent(this);
            Components.Add(_actorComponent);

            _collisionComponent = new CollisionComponent(this);
            Components.Add(_collisionComponent);

            _scoreComponent = new ScoreComponent(this);
            Components.Add(_scoreComponent);

            _timeComponent = new TimeComponent(this);
            Components.Add(_timeComponent);

            _speedComponent = new SpeedComponent(this);
            Components.Add(_speedComponent);

            _statusComponent = new StatusComponent(this);
            Components.Add(_statusComponent);
        }
コード例 #8
0
        public override void ApplyInterpolation(ActorComponent component, float time, KeyFrame toFrame, float mix)
        {
            switch (m_InterpolationType)
            {
            case KeyFrame.InterpolationTypes.Mirrored:
            case KeyFrame.InterpolationTypes.Asymmetric:
            case KeyFrame.InterpolationTypes.Disconnected:
            {
                ValueTimeCurveInterpolator interpolator = m_Interpolator as ValueTimeCurveInterpolator;
                if (interpolator != null)
                {
                    float v = (float)interpolator.Get((double)time);
                    SetValue(component, v, mix);
                }
                break;
            }

            case KeyFrame.InterpolationTypes.Hold:
            {
                SetValue(component, m_Value, mix);
                break;
            }

            case KeyFrame.InterpolationTypes.Linear:
            {
                KeyFrameInt to = toFrame as KeyFrameInt;

                float f = (time - m_Time) / (to.m_Time - m_Time);
                SetValue(component, m_Value * (1.0f - f) + to.m_Value * f, mix);
                break;
            }
            }
        }
コード例 #9
0
        protected override void OnInitialize()
        {
            var entity = this.characterMapper.ToEntity(new CharacterData {
                UnitId = 1
            }).Entity;

            this.dummy = entity.GetComponent <ActorComponent>();
            this.dummy.transform.rotation    = Quaternion.identity;
            this.dummy.transform.position    = new Vector3(0, -2, 0);
            this.dummy.transform.localScale *= 3.0f;

            View.Create             += OnCreate;
            View.Cancel             += OnCancel;
            View.HairColorChanged   += OnHairColorChanged;
            View.BeardColorChanged  += OnBeardColorChanged;
            View.SkinColorChanged   += OnSkinColorChanged;
            View.HairstyleChanged   += OnHairstyleChanged;
            View.BeardChanged       += OnBeardChanged;
            View.BackgroundSelected += OnBackgroundSelected;

            var customization = CharacterCustomizationValues.Instance;

            View.Construct(this.backgroundRepository.FindAll(), customization.HairColors, customization.SkinColors,
                           customization.Hairstyles.Count, customization.Beards.Count);
        }
コード例 #10
0
 public static void Awake(this ActorComponent self, IEntityActorHandler iEntityActorHandler)
 {
     self.entityActorHandler = iEntityActorHandler;
     self.queue   = new EQueue <ActorMessageInfo>();
     self.actorId = self.Entity.Id;
     Game.Scene.GetComponent <ActorManagerComponent>().Add(self.Entity);
     self.HandleAsync();
 }
コード例 #11
0
 public static void Awake(this ActorComponent self)
 {
     self.entityActorHandler = new CommonEntityActorHandler();
     self.queue   = new Queue <ActorMessageInfo>();
     self.actorId = self.Entity.Id;
     Game.Scene.GetComponent <ActorManagerComponent>().Add((Entity)self.Parent);
     self.HandleAsync();
 }
コード例 #12
0
        public override void Apply(Entity entity)
        {
            previousActorComponent = entity.GetComponent <ActorComponent>();
            entity.RemoveComponent(previousActorComponent);

            entity.AddComponent(new ConfusedMonsterAI());
            entity.Tags.Add(Tags.Confused);
        }
コード例 #13
0
 public AnimationEventArgs(string name, ActorComponent component, PropertyTypes type, float keyframeTime, float elapsedTime)
 {
     m_Name         = name;
     m_Component    = component;
     m_PropertyType = type;
     m_KeyFrameTime = keyframeTime;
     m_ElapsedTime  = elapsedTime;
 }
コード例 #14
0
ファイル: ActorComponent.cs プロジェクト: jcoder58/Plugins
            internal static unsafe void Invoke(IntPtr obj, ActorComponent PrerequisiteComponent)
            {
                long *p = stackalloc long[] { 0L, 0L };
                byte *b = (byte *)p;

                *((IntPtr *)(b + 0)) = PrerequisiteComponent;
                Main.GetProcessEvent(obj, AddTickPrerequisiteComponent_ptr, new IntPtr(p));;
            }
        }
コード例 #15
0
 private bool TryGetOrOpenUI(ActorComponent actor, SignalLinkerComponent linker, [NotNullWhen(true)] out BoundUserInterface?bui)
 {
     if (_userInterfaceSystem.TryGetUi(linker.Owner, SignalLinkerUiKey.Key, out bui))
     {
         bui.Open(actor.PlayerSession);
         return(true);
     }
     return(false);
 }
コード例 #16
0
ファイル: Actor_Component.cs プロジェクト: fqkw6/AStartTest
    // 添加组件
    protected void AddComponent(ActorComponent component)
    {
        if (component == null)
        {
            return;
        }

        _components[component.GetType().FullName] = component;
        component.OnInit(this);
    }
コード例 #17
0
        public static KeyFrame Read(BinaryReader reader, ActorComponent component)
        {
            KeyFrameIntProperty frame = new KeyFrameIntProperty();

            if (KeyFrameInt.Read(reader, frame))
            {
                return(frame);
            }
            return(null);
        }
コード例 #18
0
        public static KeyFrame Read(BinaryReader reader, ActorComponent component)
        {
            KeyFrameOpacity frame = new KeyFrameOpacity();

            if (KeyFrameNumeric.Read(reader, frame))
            {
                return(frame);
            }
            return(null);
        }
コード例 #19
0
        protected override void SetValue(ActorComponent component, float value, float mix)
        {
            ActorBone bone = component as ActorBone;

            if (bone == null)
            {
                return;
            }
            bone.Length = bone.Length * (1.0f - mix) + value * mix;
        }
コード例 #20
0
        public static KeyFrame Read(BinaryReader reader, ActorComponent component)
        {
            KeyFrameTrigger frame = new KeyFrameTrigger();

            if (!KeyFrame.Read(reader, frame))
            {
                return(null);
            }
            return(frame);
        }
コード例 #21
0
        public static KeyFrame Read(BinaryReader reader, ActorComponent component)
        {
            KeyFrameConstraintStrength frame = new KeyFrameConstraintStrength();

            if (KeyFrameNumeric.Read(reader, frame))
            {
                return(frame);
            }
            return(null);
        }
コード例 #22
0
    public void RmComp(string name)
    {
        ActorComponent find = null;

        find = this.components.Find(element => element.name.Equals(name));
        if (find != null)
        {
            this.components.Remove(find);
        }
    }
コード例 #23
0
        private static Task <ActorMessageInfo> GetAsync(this ActorComponent self)
        {
            if (self.Queue.Count > 0)
            {
                return(Task.FromResult(self.Queue.Dequeue()));
            }

            self.Tcs = new TaskCompletionSource <ActorMessageInfo>();
            return(self.Tcs.Task);
        }
コード例 #24
0
        public static KeyFrame Read(BinaryReader reader, ActorComponent component)
        {
            KeyFrameCollisionEnabledProperty frame = new KeyFrameCollisionEnabledProperty();

            if (!KeyFrame.Read(reader, frame))
            {
                return(null);
            }
            frame.m_Value = reader.ReadByte() == 1;
            return(frame);
        }
コード例 #25
0
        public static KeyFrame Read(BinaryReader reader, ActorComponent component)
        {
            KeyFrameStringProperty frame = new KeyFrameStringProperty();

            if (!KeyFrame.Read(reader, frame))
            {
                return(null);
            }
            frame.m_Value = Actor.ReadString(reader);
            return(frame);
        }
コード例 #26
0
        public static KeyFrame Read(BinaryReader reader, ActorComponent component)
        {
            KeyFrameActiveChild frame = new KeyFrameActiveChild();

            if (!KeyFrame.Read(reader, frame))
            {
                return(null);
            }
            frame.m_Value = (uint)reader.ReadSingle();
            return(frame);
        }
コード例 #27
0
        public override void AddComponent(ActorComponent actorComponent)
        {
            base.AddComponent(actorComponent);
            var renrdbl = actorComponent as IRenderable;

            if (renrdbl != null)
            {
                renderables.Add(new CompRendr {
                    comp = actorComponent, rndbl = renrdbl
                });
            }
        }
コード例 #28
0
        public override void Apply(ActorComponent component, float mix)
        {
            Actor actor = component.Actor;

            foreach (DrawOrderIndex doi in m_OrderedNodes)
            {
                ActorImage actorImage = actor[doi.nodeIdx] as ActorImage;
                if (actorImage != null)
                {
                    actorImage.DrawOrder = doi.order;
                }
            }
        }
コード例 #29
0
ファイル: Actor.cs プロジェクト: Noortvel/GEAsteroid
        public virtual void AddComponent(ActorComponent actorComponent)
        {
            actorComponents.Add(actorComponent);
            AddSubObject(actorComponent);
            var updbl = actorComponent as IUpdatable;

            if (updbl != null)
            {
                updatablesComponents.Add(new CompUpd {
                    comp = actorComponent, updp = updbl
                });
            }
        }
コード例 #30
0
ファイル: ActorSystem.cs プロジェクト: wang10998588/Egametang
		public static void Add(this ActorComponent self, ActorMessageInfo info)
		{
			self.queue.Enqueue(info);

			if (self.tcs == null)
			{
				return;
			}

			var t = self.tcs;
			self.tcs = null;
			t.SetResult(self.queue.Dequeue());
		}
コード例 #31
0
    /// <summary>
    /// Get the actor's bounds in world-coordinates.
    /// </summary>
    /// <param name="actor">The actor.</param>
    /// <returns>The bounds.</returns>
    public RectI GetBounds(ActorComponent actor)
    {
        // Cast a ray at the bottom left and top right corners of the viewport
        Ray bottomRay = Camera.main.ViewportPointToRay(new Vector3(0, 0, 0));
        Ray topRay = Camera.main.ViewportPointToRay(new Vector3(1, 1, 0));

        // Determine the distance to Z=0 along the ray vector (since the ray will be at an angle)
        float bottomDistance;
        float topDistance;
        if (this.planeZ.Raycast(bottomRay, out bottomDistance) && this.planeZ.Raycast(topRay, out topDistance))
        {
            // Get the position where the ray intersects the Z=0 plane
            Vector3 bottom = bottomRay.GetPoint(Math.Abs(bottomDistance));
            Vector3 top = topRay.GetPoint(Math.Abs(topDistance));

            return new RectI((int)bottom.x - 2, (int)top.y + 1, (int)(top.x - bottom.x) + 4, (int)(top.y - bottom.y) + 2);
        }
        else
        {
            return RectI.Empty;
        }
    }