public void Remove(GameObjectComponent go)
 {
     GameObject.Destroy(go.gameObject);
     go.transform      = null;
     go.gameObject     = null;
     go.spriteRenderer = null;
 }
        public TeleportAroundTargetLogic(AroundTargetMode info, Character caster,
                                         Environment environment, Skill skill)
        {
            this.info        = info;
            this.caster      = caster;
            this.environment = environment;
            this.skill       = skill;

            Entity entity = caster.GameObject().GetComponent <EntityReference>().Entity;

            movementComponent = entity.GetComponent <MovementComponent>();
            StatsComponent statsComponent = entity.GetComponent <StatsComponent>();

            invisibleStats      = statsComponent.CharacterStats.FindStats(StatsType.Invisible);
            gameObjectComponent = (GameObjectComponent)entity.GetComponent <EntityGameObjectComponent>();
            FrameAndSecondsConverter fasc = FrameAndSecondsConverter._30Fps;

            delay           = fasc.FramesToSeconds(info.delay);
            prepareDelay    = fasc.FramesToSeconds(info.prepareDelay);
            prepareEndDelay = delay + info.duration - fasc.FramesToSeconds(info.endPreceding);
            if (delay == 0)
            {
                skill.TriggerEventWithId(info.prepareEventId);
                Perform();
                isPrepareEventDispatched = true;
                prepareDispatchCount++;
            }

            if (prepareDelay == 0 && prepareDispatchCount < info.count)
            {
                skill.TriggerEventWithId(info.prepareEventId);
                isPrepareEventDispatched = true;
                prepareDispatchCount++;
            }
        }
        public Entity AddGameObject(UnityEngine.GameObject newGameObject)
        {
            var component = new GameObjectComponent();

            component.gameObject = newGameObject;
            return(AddGameObject(component));
        }
 void removeGameObject(GameObjectComponent component)
 {
     component.gameObject.SetActive(false);
     if (component.isPoolable)
         addToPool(component);
     else
         UnityEngine.Object.Destroy(component.gameObject);
 }
 public void Update(GameObjectComponent go, PositionComponent position, SizeComponent size, ColorComponent color)
 {
     go.transform.position   = position.value;
     go.transform.localScale = Vector2.one * Mathf.MoveTowards(go.transform.localScale.x, size.value * 11f, Mathf.Max(0.01f, Mathf.Abs(go.transform.localScale.x - size.value)) * 10f * Time.deltaTime);
     go.spriteRenderer.color = color.value;
     //go.trailRenderer.startColor = color.value;
     //go.trailRenderer.endColor = color.value;
 }
示例#6
0
        public ScaleModifier(ModifierInfo info, Entity casterEntity, Entity targetEntity,
                             Environment environment,
                             CollectionOfInteractions modifierInteractionCollection) : base(info, casterEntity, targetEntity, environment, modifierInteractionCollection)
        {
            this.info = (ScaleInfo)info;

            gameObjectComponent = (GameObjectComponent)targetEntity.GetComponent <EntityGameObjectComponent>();
            originalScaleValue  = gameObjectComponent.GetScale();
        }
示例#7
0
 public void Add(GameObjectComponent e, PositionComponent position, SizeComponent size, ColorComponent color)
 {
     e.gameObject            = new GameObject("Entity");
     e.transform             = e.gameObject.transform;
     e.transform.localScale  = Vector2.one * 0.001f;
     e.spriteRenderer        = e.gameObject.AddComponent <SpriteRenderer>();
     e.spriteRenderer.sprite = UnityEditor.AssetDatabase.GetBuiltinExtraResource <Sprite>("UI/Skin/Knob.psd");
     Update(e, position, size, color);
 }
示例#8
0
    void OnSpawnTail(SpawnEvent data)
    {
        Debug.Log("Spawn tail");
        SnakeComponent      snake   = _world.GetComponent <SnakeComponent> (_snakeEntity);
        GameObjectComponent snakeGO = _world.GetComponent <GameObjectComponent> (_snakeEntity);
        GameObject          tail    = GameObject.Instantiate(_tailPrefab, snakeGO.Transform.localPosition, Quaternion.identity);

        snake.Tail.Insert(0, tail.transform);
    }
 public Entity ReplaceGameObject(UnityEngine.GameObject newGameObject)
 {
     GameObjectComponent component;
     if (hasGameObject) {
         WillRemoveComponent(ComponentIds.GameObject);
         component = gameObject;
     } else {
         component = new GameObjectComponent();
     }
     component.gameObject = newGameObject;
     return ReplaceComponent(ComponentIds.GameObject, component);
 }
示例#10
0
    public void Execute()
    {
        foreach (Entity e in _group.GetEntities())
        {
            Vector2             velocity   = e.velocity.vel;
            GameObjectComponent gameObject = e.gameObject;

            float angle = (float)Math.Atan2(velocity.y, velocity.x) * Mathf.Rad2Deg;

            gameObject.gameObject.transform.rotation = Quaternion.AngleAxis(angle, Vector3.forward);
        }
    }
示例#11
0
    public void CreateFrom(GameObjectComponent gameObject, PositionComponent source, PositionComponent target)
    {
        gameObject.entity.gameObject = null;//解除和原entity的关系

        EatingComponent comp = new EatingComponent();

        comp.go          = gameObject;
        comp.target      = target;
        comp.startOffest = source.value - target.value;
        comp.endOffest   = Vector2.Lerp(source.value, target.value, 0.5f) - target.value;
        comp.Start();
        world.eatings.DelayAdd(comp);
    }
示例#12
0
        void m_launcherSelectionDelayTimer_OnTime(Timer source)
        {
            if (Arena == null)
            {
                return;
            }

            Arena.SelectedLauncher.Select();
            GameObjectComponent launcher = (GameObjectComponent)Arena.SelectedLauncher;

            Camera.Focus(launcher.Owner);
            m_launcherSelectionFeedbackTimer.Start();
        }
        public InvisibleModifier(ModifierInfo info, Entity casterEntity,
                                 Entity targetEntity, Environment environment,
                                 CollectionOfInteractions modifierInteractionCollection) : base(info, casterEntity, targetEntity, environment, modifierInteractionCollection)
        {
            this.targetEntity = targetEntity;
            this.info         = (InvisibleInfo)info;

            StatsComponent targetStatsComponent = targetEntity.GetComponent <StatsComponent>();
            bool           found;

            invisibleStats      = targetStatsComponent.CharacterStats.FindStats(StatsType.Invisible, out found);
            gameObjectComponent = (GameObjectComponent)targetEntity.GetComponent <EntityGameObjectComponent>();
        }
        private IGameObject createGameObject(GameObjectComponent comp)
        {
            var subs = Substitute.For <IGameObject>();

            subs.Set <GameObjectComponent>(comp);
            subs.Equals(null).Returns(delegate(CallInfo info)
            {
                var other = info.Args()[0] as IGameObject;
                var comp2 = other.Get <GameObjectComponent>();
                return(comp.Equals(comp2));
            });

            return(subs);
        }
示例#15
0
        private void AddComponents(ObjectModel model, BeatEmUpGame game, GameObject gameObject)
        {
            if (model.HasComponents())
            {
                for (int i = 0; i < model.ComponentNames.Length; i++)
                {
                    GameObjectComponent component = game.CreateComponent(model.ComponentNames[i], gameObject);

                    if (component != null)
                    {
                        gameObject.AddComponent(component);
                    }
                }
            }
        }
示例#16
0
    public void Execute()
    {
        float deltaTime = _time.GetSingleEntity().time.deltaTime;

        foreach (Entity e in _group.GetEntities())
        {
            AlphaComponent alpha = e.alpha;
            alpha.time -= deltaTime;
            GameObjectComponent gameobject = e.gameObject;

            SpriteRenderer renderer = gameobject.gameObject.GetComponent <SpriteRenderer>();
            Color          color    = renderer.color;
            renderer.color = new Color(color.r, color.g, color.b, alpha.time / alpha.totalTime);
        }
    }
        public void TestPersistSingleComponentState()
        {
            var persister = new ObjectPersister();

            var comp = new GameObjectComponent();

            comp.SetTestData();

            var data = persister.SerializeObjectState(comp);

            var comp2 = new GameObjectComponent();

            persister.DeserializeObjectState(comp2, data);
            Assert.True(comp.Equals(comp2));
        }
示例#18
0
        protected override void OnDelayedAttachAsMain(Character target)
        {
            target.InterruptChannelingSkill();
            targetStatsComponent      = targetEntity.GetComponent <StatsComponent>();
            targetGameObjectComponent = (GameObjectComponent)targetEntity.GetComponent <EntityGameObjectComponent>();
            targetMovementComponent   = targetEntity.GetComponent <MovementComponent>();

            bool found;

            targetVanishStats = targetStatsComponent.CharacterStats.FindStats(StatsType.Vanish, out found);
            targetVanishStats.SetBaseBoolValue(true);
            targetGameObjectComponent.DisableRendererObject();

            casterMovementComponent = casterEntity.GetComponent <MovementComponent>();
        }
        public Entity ReplaceGameObject(UnityEngine.GameObject newGameObject)
        {
            GameObjectComponent component;

            if (hasGameObject)
            {
                WillRemoveComponent(ComponentIds.GameObject);
                component = gameObject;
            }
            else
            {
                component = new GameObjectComponent();
            }
            component.gameObject = newGameObject;
            return(ReplaceComponent(ComponentIds.GameObject, component));
        }
    void addToPool(GameObjectComponent gameObjectComponent)
    {
        string name = gameObjectComponent.path;
        bool wasObjectAdded = false;

        foreach (Entity e in _poolGroup.GetEntities()) {
            if (e.poolableGO.name.Equals(name)) {
                wasObjectAdded = true;
                e.poolableGO.queue.Enqueue(gameObjectComponent.gameObject);
            }
        }
        if (!wasObjectAdded) {
            Entity e = _pool.CreateEntity()
                .AddPoolableGO(name, new Queue<GameObject>());
            e.poolableGO.queue.Enqueue(gameObjectComponent.gameObject);
        }
    }
        public void Test()
        {
            var persister = new GameObjectPersister();

            var comp = new GameObjectComponent();

            comp.SetTestData();

            var obj = createGameObject(comp);

            var data = persister.SerializeGameObject(obj);


            var obj2 = persister.DeserializeGameObject(data);

            Assert.True(obj.Equals(obj2));
        }
示例#22
0
    void addToPool(GameObjectComponent gameObjectComponent)
    {
        string name           = gameObjectComponent.path;
        bool   wasObjectAdded = false;

        foreach (Entity e in _poolGroup.GetEntities())
        {
            if (e.poolableGO.name.Equals(name))
            {
                wasObjectAdded = true;
                e.poolableGO.queue.Enqueue(gameObjectComponent.gameObject);
            }
        }
        if (!wasObjectAdded)
        {
            Entity e = _pool.CreateEntity()
                       .AddPoolableGO(name, new Queue <GameObject>());
            e.poolableGO.queue.Enqueue(gameObjectComponent.gameObject);
        }
    }
示例#23
0
    /// <summary>
    /// Get IEntity object with specified GameObject prefab.
    /// </summary>
    /// <param name="prefab">GameObject to instantiate.</param>
    /// <param name="position">Start position.</param>
    /// <param name="rotation">Start rotation.</param>
    /// <param name="parent">The parent to attach an object to.</param>
    public IEntity Get(GameObject prefab, Vector3 position, Quaternion rotation, Transform parent)
    {
        if (maxPoolSize == 0)
        {
            return(CreateStandardEntity(prefab, position, rotation, parent, true));
        }

        DestroyOutOfRangeObjects();
        int index = FindFreeObjectInPool();

        if (index != -1)
        {
            IEntity entity = pool[index];
            ref GameObjectComponent gameObjectComponent = ref entity.GetComponent <GameObjectComponent>();
            gameObjectComponent.SelfTransform.position = position;
            gameObjectComponent.SelfTransform.rotation = rotation;
            gameObjectComponent.SelfTransform.parent   = parent;
            gameObjectComponent.Self.SetActive(true);
            SetUsage(index, true);

            return(entity);
        }
示例#24
0
 public Entity()
 {
     gameObject = new GameObjectComponent()
     {
         entity = this
     };
     position = new PositionComponent()
     {
         entity = this
     };
     size = new SizeComponent()
     {
         entity = this
     };
     color = new ColorComponent()
     {
         entity = this
     };
     team = new TeamComponent()
     {
         entity = this
     };
 }
示例#25
0
 public void Add(GameObjectComponent e, PositionComponent position, SizeComponent size, ColorComponent color, bool isplayer = false)
 {
     e.gameObject           = new GameObject("Entity");
     e.transform            = e.gameObject.transform;
     e.transform.localScale = Vector2.one * 0.001f;
     e.spriteRenderer       = e.gameObject.AddComponent <SpriteRenderer>();
     //e.spriteRenderer.sprite = UnityEditor.AssetDatabase.GetBuiltinExtraResource<Sprite>("UI/Skin/Knob.psd");
     if (isplayer == false)
     {
         e.spriteRenderer.sprite = Resources.Load <Sprite>("ball");
     }
     else
     {
         e.spriteRenderer.sprite = Resources.Load <Sprite>("player");
     }
     //e.lineRenderer = e.gameObject.AddComponent<LineRenderer>();
     ////e.lineRenderer.material = UnityEditor.AssetDatabase.GetBuiltinExtraResource<Material>("Sprites-Default");
     //e.lineRenderer.material = Resources.Load<Material>("1");
     //e.lineRenderer.useWorldSpace = false;
     //e.lineRenderer.startWidth = 0.1f;
     //e.lineRenderer.endWidth = 0;
     //e.lineRenderer.numCapVertices = 5;
     //e.trailRenderer = e.gameObject.AddComponent<TrailRenderer>();
     //e.trailRenderer.material = Resources.Load<Material>("1");
     //e.trailRenderer.startWidth = 0.1f;
     //e.trailRenderer.endWidth = 0;
     //e.trailRenderer.numCapVertices = 5;
     if (isplayer)
     {
         //添加蛇尾
         //var trail = new GameObject("TRAIL");
         var trail = GameObject.Instantiate(Resources.Load <GameObject>("trail"), e.gameObject.transform);
         trail.transform.localPosition = Vector3.zero;
         //trail.transform.parent = e.gameObject.transform;
     }
     Update(e, position, size, color);
 }
        public HitboxTransformModifier(ModifierInfo info, Entity casterEntity,
                                       Entity targetEntity, Environment environment,
                                       CollectionOfInteractions modifierInteractionCollection) : base(info, casterEntity, targetEntity, environment, modifierInteractionCollection)
        {
            this.info = (HitboxTransformInfo)info;
            GameObjectComponent goc = (GameObjectComponent)targetEntity.GetComponent <EntityGameObjectComponent>();

            collider       = (BoxCollider)goc.Collider;
            sortedHitboxes = new List <Hitbox>(this.info.HtmcConfig.hitboxes);
            sortedHitboxes.Sort((a, b) => {
                float diff = a.frame - b.frame;
                if (diff > 0)
                {
                    return(1);
                }

                if (diff < 0)
                {
                    return(-1);
                }

                return(0);
            });
        }
示例#27
0
        internal void Update(float deltaTime)
        {
            if (!IsEnabled)
            {
                return;
            }

            this.updatingChildren.Clear();
            this.updatingChildren.AddRange(Children);

            for (int i = this.components.Count - 1; i >= 0; i--)
            {
                GameObjectComponent component = this.components[i];

                if (!component.IsActive)
                {
                    continue;
                }

                component.Update(deltaTime);
            }

            foreach (GameObject child in this.updatingChildren)
            {
                child.Update(deltaTime);
            }

            /*if (!Rigidbody.IsKinematic)
             *  Speed.Y -= Data.PHYSICS_GRAV * Rigidbody.Mass;
             *
             * appliedVelocity.Set(Speed).Scale(deltaTime);
             *
             * // collision handling
             * if (!Rigidbody.IsKinematic) {
             *  for (int i = 0; i < Game.Instance.GameObjects.Count(); i++) {
             *      GameObject gO = Game.Instance.GameObjects.ElementAt(i);
             *
             *      if (this == gO)
             *          continue;
             *
             *      Vector2 relativeTranslation = new Vector2(gO.Speed).Subtract(Speed).Scale(deltaTime);
             *      CollisionResult cR = Collide(gO, relativeTranslation);
             *
             *      if (cR.IsTriggerCollision)
             *          continue;
             *
             *      if (cR.WillIntersect) {
             *          appliedVelocity.Add(cR.TranslationVector);
             *
             *          if (cR.TranslationVector.X != 0)
             *              Speed.X = 0;
             *
             *          if (cR.TranslationVector.Y != 0)
             *              Speed.Y = 0;
             *      }
             *
             *  }
             *
             * }
             *
             * Position.Add(appliedVelocity);
             *
             * Speed.Set(0, 0);
             *
             * //if (wouldHaveIntersected)
             * //    Speed.Set();*/
        }
 public Entity AddGameObject(UnityEngine.GameObject newGameObject)
 {
     var component = new GameObjectComponent();
     component.gameObject = newGameObject;
     return AddGameObject(component);
 }
示例#29
0
 void removeGameObject(GameObjectComponent component)
 {
     component.gameObject.transform.parent = null;
     component.gameObject.SetActive(false);
     addToPool(component);
 }
示例#30
0
 public void SetToTop(GameObjectComponent go)
 {
     go.gameObject.AddComponent <SortingGroup>().sortingOrder = 1;
 }
示例#31
0
 public MenuScaleFx(TextComponent textCmp)
 {
     m_targetCmp = textCmp;
 }
示例#32
0
 public MenuScaleFx(SpriteComponent sprtieComponent)
 {
     m_targetCmp = sprtieComponent;
 }
 protected bool Equals(GameObjectComponent other)
 {
     return(data1 == other.data1 && data2 == other.data2 && vector.Equals(other.vector) &&
            data3 == other.data3 && string.Equals(Number, other.Number));
 }
示例#34
0
 public void AddComponent(GameObjectComponent component)
 {
     components.Add(component);
 }
 void removeGameObject(GameObjectComponent component)
 {
     component.gameObject.transform.parent = null;
     component.gameObject.SetActive(false);
     addToPool(component);
 }
 public Entity AddGameObject(GameObjectComponent component)
 {
     return AddComponent(ComponentIds.GameObject, component);
 }
 public Entity AddGameObject(GameObjectComponent component)
 {
     return(AddComponent(ComponentIds.GameObject, component));
 }