示例#1
0
 public SpawnOnEvent(SerializationInfo info, StreamingContext context)
 {
     Start            = info.GetValue(nameof(Start), Start);
     End              = info.GetValue(nameof(End), End);
     Parent           = info.GetValue(nameof(Parent), Parent);
     ActiveGameObject = Serializer.GetPrefabEntity(info.GetValue(nameof(ActiveGameObject), -1));
 }
 public void OnCreate(PrefabEntity entity)
 {
     if (_particleSystem == null)
     {
         _particleSystem = GetComponent <ParticleSystem>();
     }
 }
        public GameObject ToGameObject(Transform parent)
        {
            GameObject   go = null;
            PrefabEntity mc = null;

            // switch (_metadata.AssetType) {
            //     case AssetType.Prefab:
            //         mc = ItemPool.Spawn(_metadata.PrefabPath);
            //         if (mc != null) {
            //             go = mc.gameObject;
            //             //Metadata.ComponentDiff.ApplyPatch(go);
            //         }
            //         break;
            // }
            if (go == null)
            {
                go = new GameObject();
                mc = go.GetOrAddComponent <PrefabEntity>();
                AddComponentsToNewGo(go);
            }
            mc.Metadata = _metadata;
            go.name     = _name;
            if (parent != null)
            {
                go.transform.SetParent(parent);
            }
            _tr.Restore(go.transform);
            foreach (var childNode in _children)
            {
                var child = childNode.ToGameObject(go.transform);
                child.transform.SetParent(go.transform);
            }
            return(go);
        }
示例#4
0
 public CachedAnimator(IAnimator value)
 {
     _value = value;
     if (value is UnityEngine.Component unityComponent)
     {
         var prefab = PrefabEntity.FindPrefabRoot(unityComponent.transform);
         if (prefab != null)
         {
             _serializedId   = prefab.Metadata.SerializationId;
             _transformChild = unityComponent.transform.GetPath();
         }
         else
         {
             Debug.LogErrorFormat("{0}: unable to find prefab root on {1}", value.GetType(), unityComponent.gameObject.name);
         }
         return;
     }
     if (value is IComponent ecsComponent)
     {
         _componentType = value.GetType();
         _entityId      = EntityController.GetComponentArray(_componentType).GetEntity(ecsComponent);
         return;
     }
     Debug.LogErrorFormat("{0} is not a valid type of animator", value.GetType());
 }
示例#5
0
 public void SetDatabaseEntry(PrefabEntity entity)
 {
     _prefabPath    = entity.ResourcePath;
     _assetType     = AssetType.Prefab;
     _origin        = entity.ResourcePath;
     _componentDiff = new SerializedComponentDifferences();
 }
示例#6
0
 public void Set(T component)
 {
     _value = component;
     if (_value == null)
     {
         Clear();
         return;
     }
     if (component is UnityEngine.Component unityComponent)
     {
         var prefab = PrefabEntity.FindPrefabRoot(unityComponent.transform);
         if (prefab != null)
         {
             _serializedId   = prefab.PrefabId;
             _transformChild = unityComponent.transform.GetPath();
         }
         else
         {
             Debug.LogErrorFormat("{0}: unable to find prefab root on {1}", component.GetType(), unityComponent.gameObject.name);
         }
         return;
     }
     if (component is IComponent ecsComponent)
     {
         _componentType = component.GetType();
         _entityId      = EntityController.GetComponentArray(_componentType).GetEntity(ecsComponent);
         return;
     }
     Debug.LogErrorFormat("{0} is not a valid type of animator", component.GetType());
 }
示例#7
0
 public void Handle(ActionStateEvent arg)
 {
     if (arg.State == EndEvent && _activeGameObject != null)
     {
         ItemPool.Despawn(_activeGameObject);
     }
     else if (arg.State == StartEvent && Prefab != null)
     {
         var animTr = this.Get <AnimTr>().Tr;
         if (Parent && animTr != null)
         {
             _activeGameObject = ItemPool.Spawn(Prefab);
             if (_activeGameObject != null)
             {
                 _activeGameObject.transform.SetParentResetPos(animTr);
             }
         }
         else
         {
             this.GetEntity().FindSpawn(out var spawnPos, out var spawnRot);
             _activeGameObject = ItemPool.Spawn(Prefab, spawnPos, spawnRot);
         }
         if (EndEvent == ActionStateEvents.None)
         {
             _activeGameObject = null;
         }
     }
 }
示例#8
0
 public SpawnOnEvent(ActionStateEvents startEvent, ActionStateEvents endEvent, bool parent, PrefabEntity prefab)
 {
     StartEvent = startEvent;
     EndEvent   = endEvent;
     Prefab     = prefab;
     Parent     = parent;
 }
示例#9
0
 public SpawnOnEvent(ActionState start, ActionState end, bool parent, PrefabEntity prefab)
 {
     Start  = start;
     End    = end;
     Prefab = prefab;
     Parent = parent;
 }
示例#10
0
 public virtual void OnCreate(PrefabEntity entity)
 {
     if (_hoverGraphic != null)
     {
         _defaultColor = _hoverGraphic.color;
     }
     Entity = entity;
 }
 public void OnCreate(PrefabEntity entity)
 {
     _materialBlock = new MaterialPropertyBlock();
     _renderer.GetPropertyBlock(_materialBlock);
     _resetPoint       = _pivot.localPosition;
     _frameTimer       = new Timer(1, Unscaled);
     _positionAnimator = new TweenV3();
 }
示例#12
0
 public void OnCreate(PrefabEntity entity)
 {
     _receivers = new IRenderWatcherReceiver[_receiverTargets.Length];
     for (int i = 0; i < _receiverTargets.Length; i++)
     {
         _receivers[i] = _receiverTargets[i].GetComponent <IRenderWatcherReceiver>();
     }
 }
示例#13
0
 public void OnCreate(PrefabEntity entity)
 {
     _rectTr = transform as RectTransform;
     if (_text == null)
     {
         _text = GetComponentInChildren <TextMeshProUGUI>(true);
     }
 }
示例#14
0
 public override void OnCreate(PrefabEntity entity)
 {
     base.OnCreate(entity);
     if (_label != null)
     {
         _minMainText = _label.fontSizeMin;
     }
 }
 public virtual void OnCreate(PrefabEntity entity)
 {
     Entity         = entity;
     _rectTransform = transform as RectTransform;
     if (_hoverGraphic != null)
     {
         _defaultColor = _hoverGraphic.color;
     }
 }
示例#16
0
 public void OnCreate(PrefabEntity entity)
 {
     Tr                          = transform;
     _cameraOffset               = Tr.localPosition;
     _nativeRotation             = Tr.localRotation;
     _nativeRotation.eulerAngles = Vector3.up * Tr.localEulerAngles.y;
     HoldStartPosition           = _holdTransform.localPosition;
     MessageKit.addObserver(Messages.OptionsChanged, SetOptions);
 }
示例#17
0
 public void OnCreate(PrefabEntity entity)
 {
     _lineRenderer = GetComponent <LineRenderer>();
     if (!_animateUv && _beamFrames.Length > 0)
     {
         _lineRenderer.material.mainTexture = _beamFrames[0];
     }
     _initialBeamOffset = Random.Range(0f, 5f);
 }
        public void OnCreate(PrefabEntity entity)
        {
            MaterialPropertyBlock materialBlock = new MaterialPropertyBlock();

            _renderer.GetPropertyBlock(materialBlock);
            _renderer.sprite = _sprite.GetFacingSprite(_orientation);
            materialBlock.SetTexture("_BumpMap", _sprite.NormalMap);
            materialBlock.SetTexture("_MainTex", _renderer.sprite.texture);
            _renderer.SetPropertyBlock(materialBlock);
        }
示例#19
0
        public void OnCreate(PrefabEntity entity)
        {
            MaterialPropertyBlock materialBlock = new MaterialPropertyBlock();

            _renderer.GetPropertyBlock(materialBlock);
            _renderer.sprite = _animation.GetSpriteFrame(0);
            materialBlock.SetTexture("_BumpMap", _animation.NormalMap);
            materialBlock.SetTexture("_MainTex", _renderer.sprite.texture);
            _renderer.SetPropertyBlock(materialBlock);
        }
示例#20
0
        private void SetEntityList(PrefabEntity entity)
        {
            var list = GetList(entity.SectorPosition);

            list.Add(entity);
            if (!IsActive)
            {
                return;
            }
            var active = CurrentList.Contains(entity.SectorPosition);

            entity.SetActive(active);
        }
示例#21
0
 public void SetPrefabEntity(PrefabEntity prefab)
 {
     if (prefab == null)
     {
         return;
     }
     _serializedId = prefab.Metadata.SerializationId;
     if (prefab.transform == _value.transform)
     {
         _transformChild = null;
         return;
     }
     _transformChild = _value.transform.GetPath();
 }
示例#22
0
 public void Remove(PrefabEntity entity)
 {
     _entities.Remove(entity);
     if (!_sectorObjects.TryGetValue(entity.SectorPosition, out var list))
     {
         return;
     }
     list.Remove(entity);
     if (list.Count != 0)
     {
         return;
     }
     _sectorObjects.Remove(entity.SectorPosition);
 }
        public SerializedComponentReference(PrefabEntity entity, Component component) : base(entity)
        {
            _type = component.GetType();
            var components = entity.GetComponents(_type);

            for (int i = 0; i < components.Length; i++)
            {
                if (components[i] == component)
                {
                    _componentIndex = i;
                    break;
                }
            }
        }
示例#24
0
        public void OnCreate(PrefabEntity entity)
        {
            var currencies = GameData.Enums.GetFakeEnum(EnumTypes.Currencies);

            for (int i = 0; i < currencies.Length; i++)
            {
                var prefab = ItemPool.SpawnUIPrefab(_currencyPrefab, _currencyPivot);
                prefab.GetComponentInChildren <Image>().overrideSprite = SpriteDatabase.CurrencyIcons.SafeAccess(i);
                var text = prefab.GetComponentInChildren <TextMeshProUGUI>();
                text.text = "";
                var currency = Player.GetCurrency(currencies.GetShortID(i));
                currency.OnResourceChanged += () => { text.text = currency.Value.ToString("F0"); };
            }
        }
示例#25
0
 public static void AddEntity(PrefabEntity we)
 {
     if (_currentList.ContainsKey(we.Metadata.SerializationId))
     {
         Debug.LogErrorFormat("Duplicate Id {0} current {1} parent {3} new {2}",
                              we.Metadata.SerializationId, we.name,
                              _currentList[we.Metadata.SerializationId].name,
                              we.transform.parent != null ? we.transform.parent.name : "None");
         _globalIndex = MathEx.Max(we.Metadata.SerializationId + 1, _globalIndex);
         we.Metadata.UpdateSerializedId(true);
     }
     _globalIndex = MathEx.Max(we.Metadata.SerializationId + 1, _globalIndex);
     _currentList.Add(we.Metadata.SerializationId, we);
 }
示例#26
0
 public void Set(T component)
 {
     _value = component;
     if (_value == null)
     {
         _serializedId   = -1;
         _transformChild = null;
         return;
     }
     if (_serializedId >= 0)
     {
         return;
     }
     SetPrefabEntity(PrefabEntity.FindPrefabRoot(_value.transform));
 }
示例#27
0
 public void OnCreate(PrefabEntity entity)
 {
     _renderer    = GetComponent <SpriteRenderer>();
     _boxCollider = GetComponent <BoxCollider>();
     _mc          = GetComponent <MeshCollider>();
     if (_mc != null)
     {
         UnityCollider = _mc;
         InitMeshCollider();
     }
     else
     {
         UnityCollider = _boxCollider;
     }
 }
示例#28
0
        public override void OnCreate(PrefabEntity entity)
        {
            base.OnCreate(entity);
#if Animancer
            if (_mask != null)
            {
                Controller.SetLayerMask(Layer, _mask);
            }
#endif
            if (!IsSecondary)
            {
                PlayAnimation(PlayerAnimationIds.Idle, false);
            }
            //else {
            //    Controller.SetLayerAdditive(Layer, true);
            //}
        }
示例#29
0
        public void OnCreate(PrefabEntity entity)
        {
            MaterialPropertyBlock materialBlock = new MaterialPropertyBlock();

            _renderer.GetPropertyBlock(materialBlock);
            _spriteCollider = _renderer.GetComponent <SpriteCollider>();
            if (_sprite == null)
            {
                return;
            }
            _renderer.sprite = _sprite.GetSpriteFrame(0);
            materialBlock.SetTexture("_BumpMap", _sprite.NormalMap);
            materialBlock.SetTexture("_MainTex", _renderer.sprite.texture);
            _renderer.SetPropertyBlock(materialBlock);
            if (_spriteCollider != null)
            {
                _spriteCollider.UpdateCollider();
            }
        }
示例#30
0
        public void OnCreate(PrefabEntity entity)
        {
            _interpolator  = new CooperativePathInterpolator(this);
            _seeker        = GetComponent <Seeker>();
            _rvoController = GetComponent <RVOController>();
            _traversal     = new NpcMovementManager.TraversalProvider(this);
            Tr             = transform;
            var colliderComponent = GetComponent <Collider>();

            if (colliderComponent != null)
            {
                LocalCenter = new Vector3(0, colliderComponent.bounds.size.y / 2, 0);
            }
            else
            {
                LocalCenter = Vector3.up;
            }
            if (GameOptions.Get("DebugPathfinding", false))
            {
                _debugRenderer = gameObject.AddComponent <LineRenderer>();
                _debugRenderer.widthMultiplier = 0.3f;
            }
        }