void IEntityAwakeHandler.OnEntityAwake(SPEntity entity)
        {
            if (_initialized)
            {
                return;
            }

            _initialized = true;
            this.Init(entity, _controller);
        }
        public static object GetAsFromSource(System.Type tp, object obj)
        {
            if (obj == null)
            {
                return(null);
            }

            var otp = obj.GetType();

            if (TypeUtil.IsType(otp, tp))
            {
                return(obj);
            }
            if (obj is IComponent)
            {
                var c = (obj as IComponent).component;
                if (!object.ReferenceEquals(c, null) && TypeUtil.IsType(c.GetType(), tp))
                {
                    return(c);
                }
            }

            var go = GameObjectUtil.GetGameObjectFromSource(obj);

            if (tp == typeof(UnityEngine.GameObject))
            {
                return(go);
            }

            if (go != null)
            {
                if (typeof(SPEntity).IsAssignableFrom(tp))
                {
                    return(SPEntity.GetEntityFromSource(tp, go));
                }
                else if (ComponentUtil.IsAcceptableComponentType(tp))
                {
                    return(go.GetComponent(tp));
                }
            }

            return(null);
        }
        public static T GetAsFromSource <T>(object obj) where T : class
        {
            if (obj == null)
            {
                return(null);
            }
            if (obj is T)
            {
                return(obj as T);
            }
            if (obj is IComponent)
            {
                var c = (obj as IComponent).component;
                if (c is T)
                {
                    return(c as T);
                }
            }
            var go = GameObjectUtil.GetGameObjectFromSource(obj);

            if (go is T)
            {
                return(go as T);
            }

            //if (go != null && ComponentUtil.IsAcceptableComponentType(typeof(T))) return go.GetComponentAlt<T>();
            if (go != null)
            {
                var tp = typeof(T);
                if (typeof(SPEntity).IsAssignableFrom(tp))
                {
                    return(SPEntity.GetEntityFromSource(tp, go) as T);
                }
                else if (ComponentUtil.IsAcceptableComponentType(tp))
                {
                    return(go.GetComponent(tp) as T);
                }
            }

            return(null);
        }
 protected abstract void Init(SPEntity entity, SPAnimationController controller);
Example #5
0
        public static bool TestCursorOverEntity(Camera cursorCamera, Vector2 cursorPos, out SPEntity entity, float maxDistance = float.PositiveInfinity, int layerMask = Physics.AllLayers, QueryTriggerInteraction query = QueryTriggerInteraction.UseGlobal)
        {
            Collider c;

            if (TestCursorOver(cursorCamera, cursorPos, out c, maxDistance, layerMask, query))
            {
                entity = SPEntity.Pool.GetFromSource(c);
                return(!object.ReferenceEquals(entity, null));
            }
            else
            {
                entity = null;
                return(false);
            }
        }
Example #6
0
 protected abstract void Init(SPEntity entity, SPLegacyAnimController controller);
Example #7
0
        protected override void Awake()
        {
            base.Awake();

            _entity = SPEntity.Pool.GetFromSource(this);
        }