public object GetTarget(System.Type tp, object triggerArg)
        {
            if (tp == null)
            {
                throw new System.ArgumentNullException("tp");
            }

            var obj = this.ReduceTarget(triggerArg);

            if (obj == null)
            {
                return(null);
            }

            var result = ObjUtil.GetAsFromSource(tp, obj);

            if (ObjUtil.IsNullOrDestroyed(result) && this.ImplicityReducesEntireEntity && ComponentUtil.IsAcceptableComponentType(tp))
            {
                //if not configured, and the triggerArg didn't reduce properly, lets search the entity of the 'triggerArg'
                var go = GameObjectUtil.FindRoot(GameObjectUtil.GetGameObjectFromSource(obj));
                if (go == null)
                {
                    return(null);
                }
                result = go.FindComponent(tp);
            }
            return(result);
        }
        public System.Collections.IEnumerable GetTargets(System.Type tp, object triggerArg)
        {
            foreach (var obj in this.ReduceTargets(triggerArg))
            {
                if (obj == null)
                {
                    continue;
                }

                var result = ObjUtil.GetAsFromSource(tp, obj);
                if (ObjUtil.IsNullOrDestroyed(result) && !_configured && obj == triggerArg && ComponentUtil.IsAcceptableComponentType(tp))
                {
                    //if not configured, and the triggerArg didn't reduce properly, lets search the entity of the 'triggerArg'
                    var go = GameObjectUtil.FindRoot(GameObjectUtil.GetGameObjectFromSource(obj));
                    if (go == null)
                    {
                        continue;
                    }
                    result = go.FindComponent(tp);
                }
                if (result != null)
                {
                    yield return(result);
                }
            }
        }
Example #3
0
        private UnityEngine.Object ResolveTargetAnimator(object arg)
        {
            var obj = _targetAnimator.GetTarget <UnityEngine.Object>(arg);

            if (obj == null || obj is ISPAnimationSource || obj is ISPAnimator || obj is Animation)
            {
                return(obj);
            }
            else if (_targetAnimator.TargetsTriggerArg)
            {
                var go = GameObjectUtil.FindRoot(GameObjectUtil.GetGameObjectFromSource(obj));
                if (go == null)
                {
                    return(null);
                }

                SPAnimationController spcont;
                if (go.FindComponent <SPAnimationController>(out spcont))
                {
                    return(spcont);
                }

                Animation anim;
                if (go.FindComponent <Animation>(out anim))
                {
                    return(anim);
                }
            }

            return(null);
        }
Example #4
0
        public override bool Trigger(object sender, object arg)
        {
            if (!this.CanTrigger)
            {
                return(false);
            }

            var targ = this._target.GetTarget <Transform>(arg);

            if (targ == null)
            {
                return(false);
            }
            if (_teleportEntireEntity)
            {
                targ = GameObjectUtil.FindRoot(targ).transform;
            }

            var loc = _location.GetTarget <Transform>(arg);

            if (targ == null || loc == null)
            {
                return(false);
            }

            targ.position = loc.position;
            if (_orientWithLocationRotation)
            {
                targ.rotation = loc.rotation;
            }

            return(true);
        }
        public IEnumerable <T> GetTargets <T>(object triggerArg) where T : class
        {
            foreach (var obj in this.ReduceTargets(triggerArg))
            {
                if (obj == null)
                {
                    continue;
                }

                var result = ObjUtil.GetAsFromSource <T>(obj);
                if (result == null && !_configured && obj == triggerArg && ComponentUtil.IsAcceptableComponentType(typeof(T)))
                {
                    //if not configured, and the triggerArg didn't reduce properly, lets search the entity of the 'triggerArg'
                    var go = GameObjectUtil.FindRoot(GameObjectUtil.GetGameObjectFromSource(obj));
                    if (go == null)
                    {
                        continue;
                    }
                    result = go.FindComponent <T>();
                }
                if (result != null)
                {
                    yield return(result);
                }
            }
        }
        public override bool Trigger(object sender, object arg)
        {
            if (!this.CanTrigger)
            {
                return(false);
            }

            var targ = this._target.GetTarget <Transform>(arg);

            if (targ == null)
            {
                return(false);
            }
            if (_tweenEntireEntity)
            {
                targ = GameObjectUtil.FindRoot(targ).transform;
            }

            var loc = _location.GetTarget <Transform>(arg);

            if (targ == null || loc == null)
            {
                return(false);
            }

            var twn = SPTween.Tween(targ);

            twn.To("position", loc.position, _duration.Seconds);
            if (_orientWithLocationRotation)
            {
                twn.To("rotation", loc.rotation, _duration.Seconds);
            }

            twn.Use(_duration.TimeSupplier);
            twn.SetId(_target);

            if (_onComplete.Count > 0)
            {
                twn.OnFinish((t) => _onComplete.ActivateTrigger(this, null));
            }

            if (_onTick.Count > 0)
            {
                twn.OnStep((t) => _onTick.ActivateTrigger(this, null));
            }

            twn.Play(true, _tweenToken);

            return(true);
        }
        public void AddReference(T obj)
        {
            if (object.ReferenceEquals(obj, null))
            {
                throw new System.ArgumentNullException();
            }

            var go = GameObjectUtil.FindRoot(obj.gameObject);

            if (_querying)
            {
                _queryCompleteAction += () => _pool.Add(go, obj);
            }
            else
            {
                _pool.Add(go, obj);
            }
        }
        public bool RemoveReference(T obj)
        {
            if (object.ReferenceEquals(obj, null))
            {
                throw new System.ArgumentNullException();
            }

            var go = GameObjectUtil.FindRoot(obj.gameObject);
            T   cont;

            if (_pool.TryGetValue(go, out cont) && object.ReferenceEquals(cont, obj))
            {
                if (_querying)
                {
                    _queryCompleteAction += () => _pool.Remove(go);
                    return(true);
                }
                else
                {
                    return(_pool.Remove(go));
                }
            }
            else
            {
                var e = _pool.GetEnumerator();
                while (e.MoveNext())
                {
                    if (object.ReferenceEquals(e.Current.Value, obj))
                    {
                        if (_querying)
                        {
                            go = e.Current.Key;
                            _queryCompleteAction += () => _pool.Remove(go);
                        }
                        else
                        {
                            return(_pool.Remove(e.Current.Key));
                        }
                    }
                }
            }

            return(false);
        }
        private object ResolveTargetAnimator(object arg)
        {
            var obj = _targetAnimator.GetTarget <UnityEngine.Object>(arg);

            ISPAnimationSource src    = null;
            ISPAnimator        spanim = null;
            Animation          anim   = null;

            if (ObjUtil.GetAsFromSource <ISPAnimationSource>(obj, out src))
            {
                return(src);
            }
            if (ObjUtil.GetAsFromSource <ISPAnimator>(obj, out spanim))
            {
                return(spanim);
            }
            if (ObjUtil.GetAsFromSource <Animation>(obj, out anim))
            {
                return(anim);
            }

            if (_targetAnimator.ImplicityReducesEntireEntity)
            {
                var go = GameObjectUtil.FindRoot(GameObjectUtil.GetGameObjectFromSource(obj));
                if (go == null)
                {
                    return(null);
                }

                SPLegacyAnimController spcont;
                if (go.FindComponent <SPLegacyAnimController>(out spcont))
                {
                    return(spcont);
                }

                if (go.FindComponent <Animation>(out anim))
                {
                    return(anim);
                }
            }

            return(null);
        }
        /// <summary>
        /// If 'Target' is modified, this must be called to resync the cached renderers.
        /// </summary>
        public void FindRenderersInTarget()
        {
            if (_target == null || !_target.TargetsTriggerArg)
            {
                _targetRenderers = ArrayUtil.Empty <Renderer>();
                return;
            }

            var src = _target.GetTarget <GameObject>(null);

            if (src == null)
            {
                return;
            }
            if (_searchEntireEntity)
            {
                src = GameObjectUtil.FindRoot(src);
            }

            _targetRenderers = src.GetComponentsInChildren <Renderer>();
        }
        public override bool Trigger(object sender, object arg)
        {
            if (!this.CanTrigger)
            {
                return(false);
            }

            Renderer[] arr;
            if (_target.TargetsTriggerArg)
            {
                var targ = _target.GetTarget <GameObject>(arg);
                if (targ == null)
                {
                    return(false);
                }
                if (_searchEntireEntity)
                {
                    targ = GameObjectUtil.FindRoot(targ);
                }
                arr = targ.GetComponentsInChildren <Renderer>();
            }
            else
            {
                arr = _targetRenderers;
            }

            if (arr == null || arr.Length == 0)
            {
                return(false);
            }

            for (int i = 0; i < arr.Length; i++)
            {
                if (arr[i] != null)
                {
                    RendererMaterialSwap.Swap(arr[i], _material, _duration);
                }
            }
            return(true);
        }
        public T GetTarget <T>(object triggerArg) where T : class
        {
            var obj = this.ReduceTarget(triggerArg);

            if (obj == null)
            {
                return(null);
            }

            var result = ObjUtil.GetAsFromSource <T>(obj);

            if (ObjUtil.IsNullOrDestroyed(result) && this.ImplicityReducesEntireEntity && ComponentUtil.IsAcceptableComponentType(typeof(T)))
            {
                //if not configured, and the triggerArg didn't reduce properly, lets search the entity of the 'triggerArg'
                var go = GameObjectUtil.FindRoot(GameObjectUtil.GetGameObjectFromSource(obj));
                if (go == null)
                {
                    return(null);
                }
                result = go.FindComponent <T>();
            }
            return(result);
        }
Example #13
0
        public override bool Trigger(object sender, object arg)
        {
            if (!this.CanTrigger)
            {
                return(false);
            }

            var targ = _target.GetTarget <GameObject>(arg);

            if (targ == null)
            {
                return(false);
            }
            if (_targetEntireEntity)
            {
                targ = GameObjectUtil.FindRoot(targ);
            }


            MovementController controller;

            if (targ.GetComponentInChildren <MovementController>(out controller))
            {
                //controller.AddForce(this.Force.GetForce(this.transform), this.Force.ForceMode);
                this.Force.ApplyForce(this.transform, controller);
                return(true);
            }
            Rigidbody body;

            if (targ.GetComponentInChildren <Rigidbody>(out body))
            {
                this.Force.ApplyForce(this.transform, body);
                return(true);
            }

            return(false);
        }
        private object ResolveTargetAnimator(object arg)
        {
            var obj = _targetAnimator.GetTarget <UnityEngine.Object>(arg);

            ISPAnimationSource src    = null;
            ISPAnimator        spanim = null;
            Animation          anim   = null;

            if (ObjUtil.GetAsFromSource <ISPAnimationSource>(obj, out src))
            {
                return(src);
            }
            if (ObjUtil.GetAsFromSource <ISPAnimator>(obj, out spanim))
            {
                return(spanim);
            }
            if (ObjUtil.GetAsFromSource <Animation>(obj, out anim))
            {
                return(anim);
            }

            if (_targetAnimator.SearchesScene || _targetAnimator.TargetsTriggerArg)
            {
                var go = GameObjectUtil.FindRoot(GameObjectUtil.GetGameObjectFromSource(obj));
                if (go == null)
                {
                    return(null);
                }

                SPAnimationController spcont;
                if (go.FindComponent <SPAnimationController>(out spcont))
                {
                    return(spcont);
                }

                if (go.FindComponent <Animation>(out anim))
                {
                    return(anim);
                }
            }

            /*
             * if(obj == null || obj is ISPAnimationSource || obj is ISPAnimator || obj is Animation)
             * {
             *  return obj;
             * }
             * else if (_targetAnimator.Find != TriggerableTargetObject.FindCommand.Direct || _targetAnimator.TargetsTriggerArg)
             * {
             *  var go = GameObjectUtil.FindRoot(GameObjectUtil.GetGameObjectFromSource(obj));
             *  if (go == null) return null;
             *
             *  SPAnimationController spcont;
             *  if (go.FindComponent<SPAnimationController>(out spcont))
             *      return spcont;
             *
             *  Animation anim;
             *  if (go.FindComponent<Animation>(out anim))
             *      return anim;
             * }
             */

            return(null);
        }
        private object ResolveTargetAnimator(object arg)
        {
            var obj = _targetAnimator.GetTarget <UnityEngine.Object>(arg);

            ISPAnimationSource src    = null;
            ISPAnimator        spanim = null;
            Animation          anim   = null;

            if (ObjUtil.GetAsFromSource <ISPAnimationSource>(obj, out src))
            {
                return(src);
            }
            if (ObjUtil.GetAsFromSource <ISPAnimator>(obj, out spanim))
            {
                return(spanim);
            }
            if (ObjUtil.GetAsFromSource <Animation>(obj, out anim))
            {
                return(anim);
            }

            if (obj is SPEntity || _targetAnimator.ImplicityReducesEntireEntity)
            {
                var go = obj is SPEntity ? (obj as SPEntity).gameObject : GameObjectUtil.FindRoot(GameObjectUtil.GetGameObjectFromSource(obj));
                if (go == null)
                {
                    return(null);
                }

                SPAnimationController spcont;
                if (go.FindComponent <SPAnimationController>(out spcont))
                {
                    return(spcont);
                }

                if (go.FindComponent <Animation>(out anim))
                {
                    return(anim);
                }
            }

            /*
             * var obj = _targetAnimator.GetTarget<UnityEngine.Object>(arg);
             * if (obj == null || obj is SPAnimationController || obj is Animation)
             * {
             *  return obj;
             * }
             * else if (_targetAnimator.ImplicityReducesEntireEntity)
             * {
             *  var go = GameObjectUtil.FindRoot(GameObjectUtil.GetGameObjectFromSource(obj));
             *  if (go == null) return null;
             *
             *  SPAnimationController spcont;
             *  if (go.FindComponent<SPAnimationController>(out spcont))
             *      return spcont;
             *
             *  Animation anim;
             *  if (go.FindComponent<Animation>(out anim))
             *      return anim;
             * }
             */

            return(null);
        }