protected override void OnSPInspectorGUI()
        {
            this.serializedObject.Update();

            this.DrawDefaultInspectorExcept(PROP_WAYPOINTS);

            //clean nodes
            for (int i = 0; i < _nodesProp.arraySize; i++)
            {
                if (_nodesProp.GetArrayElementAtIndex(i).FindPropertyRelative(PROP_NODE_TRANSFORM).objectReferenceValue == null)
                {
                    _nodesProp.DeleteArrayElementAtIndex(i);
                    i--;
                }
            }
            //_currentNodes = this.GetCurrentNodes();

            if (_nodesProp.arraySize != _lastNodeCache.Count || !_lastNodeCache.SequenceEqual(_currentNodes))
            {
                //delete any nodes that are no longer in the collection
                for (int i = 0; i < _lastNodeCache.Count; i++)
                {
                    if (_lastNodeCache[i] != null && !_currentNodes.Contains(_lastNodeCache[i]) && _lastNodeCache[i].parent == _targ.transform)
                    {
                        ObjUtil.SmartDestroy(_lastNodeCache[i].gameObject);
                    }
                }

                //update cache
                _lastNodeCache.Clear();
                _lastNodeCache.AddRange(_currentNodes);

                //update names
                var rx = new Regex(@"^Node\d+$");
                for (int i = 0; i < _lastNodeCache.Count; i++)
                {
                    var node = _lastNodeCache[i];
                    var nm   = "Node" + i.ToString("000");
                    if (node != null && node.parent == _targ.transform && node.name != nm && rx.IsMatch(node.name))
                    {
                        node.name = nm;
                    }
                }
            }


            _nodeList.DoLayoutList();

            this.serializedObject.ApplyModifiedProperties();
        }
        public void SyncTriggers()
        {
            using (var lst = TempCollection.GetList <Collider>())
            {
                this.GetComponentsInChildren <Collider>(true, lst);

                //purge entries if necessary
                if (_colliders.Count > 0)
                {
                    using (var purge = TempCollection.GetList <Collider>())
                    {
                        var ed = _colliders.GetEnumerator();
                        while (ed.MoveNext())
                        {
                            if (!ObjUtil.IsObjectAlive(ed.Current.Key) || ed.Current.Value == null || !lst.Contains(ed.Current.Key))
                            {
                                purge.Add(ed.Current.Key);
                                ObjUtil.SmartDestroy(ed.Current.Value);
                            }
                        }
                        if (purge.Count > 0)
                        {
                            var e = purge.GetEnumerator();
                            while (e.MoveNext())
                            {
                                _colliders.Remove(e.Current);
                            }
                        }
                    }
                }

                //fill unknowns
                if (lst.Count > 0)
                {
                    var e = lst.GetEnumerator();
                    while (e.MoveNext())
                    {
                        if (!_colliders.Contains(e.Current))
                        {
                            var m = e.Current.AddComponent <CompoundTriggerMember>();
                            m.Init(this, e.Current);
                            _colliders.Add(e.Current, m);
                        }
                    }
                }
            }
        }
        public bool ApplyToGlobal()
        {
            var asset = AssetDatabase.LoadAllAssetsAtPath("ProjectSettings/InputManager.asset").FirstOrDefault();

            if (asset == null)
            {
                return(false);
            }

            var settings = ScriptableObject.CreateInstance <InputSettings>();

            try
            {
                var serializedObject = new SerializedObject(asset);
                var axes             = serializedObject.FindProperty(PROP_AXES);
                axes.arraySize = _entries.Count;

                for (int i = 0; i < _entries.Count; i++)
                {
                    var axis   = axes.GetArrayElementAtIndex(i);
                    var config = _entries[i];
                    axis.FindPropertyRelative(PROP_TYPE).enumValueIndex                 = (int)config.Type;
                    axis.FindPropertyRelative(PROP_NAME).stringValue                    = config.Name;
                    axis.FindPropertyRelative(PROP_DESCRIPTIVENAME).stringValue         = config.DescriptiveName;
                    axis.FindPropertyRelative(PROP_DESCRIPTIVENEGATIVENAME).stringValue = config.DescriptiveNameNegative;
                    axis.FindPropertyRelative(PROP_NEGATIVEBUTTON).stringValue          = config.NegativeButton;
                    axis.FindPropertyRelative(PROP_POSITIVEBUTTON).stringValue          = config.PositiveButton;
                    axis.FindPropertyRelative(PROP_ALTNEGATIVEBUTTON).stringValue       = config.AltNegativeButton;
                    axis.FindPropertyRelative(PROP_ALTPOSITIVEBUTTON).stringValue       = config.AltPositiveButton;
                    axis.FindPropertyRelative(PROP_GRAVITY).floatValue                  = config.Gravity;
                    axis.FindPropertyRelative(PROP_DEAD).floatValue        = config.Dead;
                    axis.FindPropertyRelative(PROP_SENSITIVITY).floatValue = config.Sensitivity;
                    axis.FindPropertyRelative(PROP_SNAP).boolValue         = config.Snap;
                    axis.FindPropertyRelative(PROP_INVERT).boolValue       = config.Invert;
                    axis.FindPropertyRelative(PROP_AXIS).enumValueIndex    = (int)config.Axis;
                    axis.FindPropertyRelative(PROP_JOYNUM).enumValueIndex  = (int)config.JoyNum;
                }

                serializedObject.ApplyModifiedProperties();
                return(true);
            }
            finally
            {
                ObjUtil.SmartDestroy(settings);
            }
        }
示例#4
0
        public static void Init()
        {
            if (!object.ReferenceEquals(_instance, null))
            {
                if (ObjUtil.IsDestroyed(_instance))
                {
                    ObjUtil.SmartDestroy(_instance.gameObject);
                    _instance = null;
                }
                else
                {
                    return;
                }
            }

            _instance = Services.Create <SPTween>(true, SPECIAL_NAME);
        }
        public void DestroyTarget(object target)
        {
            if (target is IProxy)
            {
                target = (target as IProxy).GetTarget();
            }
            var go = GameObjectUtil.GetGameObjectFromSource(target);

            if (go != null)
            {
                ObjUtil.SmartDestroy(go);
            }
            else if (target is UnityEngine.Object)
            {
                ObjUtil.SmartDestroy(target as UnityEngine.Object);
            }
        }
示例#6
0
        public static void Unregister <T>(bool destroyIfCan = false, bool donotSignalUnregister = false) where T : class, IService
        {
            var inst = Entry <T> .Instance;

            if (!inst.IsNullOrDestroyed())
            {
                Entry <T> .Instance = null;
                if (!donotSignalUnregister)
                {
                    inst.SignalServiceUnregistered();
                }

                if (destroyIfCan && inst is UnityEngine.Object)
                {
                    ObjUtil.SmartDestroy(inst as UnityEngine.Object);
                }
            }
        }
        /// <summary>
        /// Returns an InputSettings object for the current configuration in the global unity InputSettings.
        ///
        /// 'cleanInputConfigs' will clean up the input data pulled from the global settings, removing unnecessary
        /// data for inputs that don't need said data (example Gravity only applies to button/key configs, so is
        /// removed from non-button/key configs).
        /// </summary>
        /// <param name="cleanInputConfigs">Clean up the input data pulled from the global settings.</param>
        /// <returns></returns>
        public static InputSettings LoadGlobalInputSettings(bool cleanInputConfigs = false)
        {
            var asset = AssetDatabase.LoadAllAssetsAtPath("ProjectSettings/InputManager.asset").FirstOrDefault();

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

            var settings = ScriptableObject.CreateInstance <InputSettings>();

            if (!settings.CopyFromGlobal(cleanInputConfigs))
            {
                ObjUtil.SmartDestroy(settings);
                settings = null;
            }
            return(settings);
        }
        protected override void Awake()
        {
            base.Awake();

            if (!(this is T))
            {
                if (_destroyIfMultiple)
                {
                    ObjUtil.SmartDestroy(this);
                }
                return;
            }

            if (this.ValidateService())
            {
                this.OnValidAwake();
            }
        }
示例#9
0
            private void OnComponentDestroyed(object sender, System.EventArgs e)
            {
                GameLoopEntry.LevelWasLoaded -= this.OnLevelWasLoaded;
                this.RemoveThisAsSingleton();

                //if this isn't on the GameObjectSource, we should check if we need to delete our GameObject.
                if (!GameLoopEntry.ApplicationClosing)
                {
                    if (_target.gameObject != null && _target.gameObject != Singleton.GameObjectSource)
                    {
                        var others = _target.gameObject.GetComponents <Singleton>();
                        if (!(others.Length > 1 && !(from s in others select s.LifeCycle.HasFlag(SingletonLifeCycleRule.LivesForever)).Any()))
                        {
                            ObjUtil.SmartDestroy(_target.gameObject);
                        }
                    }
                }
            }
        public static void Init()
        {
            if (!object.ReferenceEquals(_instance, null))
            {
                if (ObjUtil.IsDestroyed(_instance))
                {
                    ObjUtil.SmartDestroy(_instance.gameObject);
                    _instance = null;
                }
                else
                {
                    return;
                }
            }

            _instance = Services.Create <SPTween>(true, SPECIAL_NAME);
            //_instance = Singleton.CreateSpecialInstance<SPTween>(SPECIAL_NAME, SingletonLifeCycleRule.LivesForever);
        }
示例#11
0
        /// <summary>
        /// Unregister a service from all the types it's associated.
        /// </summary>
        /// <param name="service"></param>
        /// <param name="destroyIfCan">Forcefully destroy the service if possible.</param>
        /// <param name="donotSignalUnregister">Suppress the signaling to the service that it is being unregistered. This is useful if a service is unregistering itself.</param>
        public static void Unregister(IService service, bool destroyIfCan = false, bool donotSignalUnregister = false)
        {
            if (service == null || !_services.Contains(service))
            {
                return;
            }

            //Remove reflected references
            ReplaceReferences(service, null);

            //Signal
            if (!donotSignalUnregister)
            {
                service.SignalServiceUnregistered();
            }

            if (destroyIfCan && service is UnityEngine.Object)
            {
                ObjUtil.SmartDestroy(service as UnityEngine.Object);
            }
        }
示例#12
0
        public static void ClearAll(bool destroyIfCan = false, bool donotSignalUnregister = false)
        {
            using (var types = TempCollection.GetSet <System.Type>(_serviceTable.Keys))
                using (var services = TempCollection.GetSet <IService>(_serviceTable.Values))
                {
                    //Replace references
                    var e2 = types.GetEnumerator();
                    while (e2.MoveNext())
                    {
                        var field = GetStaticEntryFieldInfo(e2.Current, false);
                        if (field != null)
                        {
                            field.SetValue(null, null);
                        }
                    }

                    //Signal
                    if (!donotSignalUnregister)
                    {
                        foreach (var service in services)
                        {
                            if (service is UnityEngine.Object)
                            {
                                service.SignalServiceUnregistered();
                            }
                        }
                    }

                    if (destroyIfCan)
                    {
                        foreach (var service in services)
                        {
                            if (service is UnityEngine.Object)
                            {
                                ObjUtil.SmartDestroy(service as UnityEngine.Object);
                            }
                        }
                    }
                }
        }
示例#13
0
        public static void Unregister(System.Type tp, bool destroyIfCan = false, bool donotSignalUnregister = false)
        {
            if (tp == null)
            {
                throw new System.ArgumentNullException("tp");
            }
            if (!tp.IsClass || tp.IsAbstract || !typeof(IService).IsAssignableFrom(tp))
            {
                throw new System.ArgumentException("Type must be a concrete class that implements IService.", "tp");
            }

            IService inst;

            try
            {
                var klass = typeof(Entry <>);
                klass = klass.MakeGenericType(tp);
                var field = klass.GetField("Instance", System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.Public);
                inst = field.GetValue(null) as IService;
                if (inst != null)
                {
                    field.SetValue(null, null);
                }
            }
            catch (System.Exception ex)
            {
                throw new System.InvalidOperationException("Failed to resolve type '" + tp.Name + "'.", ex);
            }

            if (!donotSignalUnregister && inst != null)
            {
                inst.SignalServiceUnregistered();
            }

            if (destroyIfCan && inst is UnityEngine.Object)
            {
                ObjUtil.SmartDestroy(inst as UnityEngine.Object);
            }
        }
        public IRadicalYieldInstruction Unload()
        {
            IRadicalYieldInstruction arg = null;

            if (_loadingOp != null)
            {
                var op = _loadingOp;
                _loadingOp = null;

                op.Cancel();
                if (_currentSceneBehaviour != null)
                {
                    if (op.LastScene == _currentSceneBehaviour)
                    {
                        _currentSceneBehaviour = null;
                    }
                    else
                    {
                        arg = _currentSceneBehaviour.EndScene();
                        if (arg != null)
                        {
                            _lastSceneBehaviour = _currentSceneBehaviour;
                            arg = this.StartRadicalCoroutine(this.ForceUnloadRoutine(arg, _lastSceneBehaviour));
                        }
                    }
                }
            }
            else if (_currentSceneBehaviour != null)
            {
                _currentSceneBehaviour.EndScene();
                if (_currentSceneBehaviour.gameObject != null)
                {
                    ObjUtil.SmartDestroy(_currentSceneBehaviour.gameObject);
                }
            }

            _currentSceneBehaviour = null;
            return(arg);
        }
 void System.IDisposable.Dispose()
 {
     ObjUtil.SmartDestroy(this);
 }