Пример #1
0
 public TempCollection FetchAll()
 {
     TempCollection coll = new TempCollection();
     Query qry = new Query(Temp.Schema);
     coll.LoadAndCloseReader(qry.ExecuteReader());
     return coll;
 }
Пример #2
0
        public static UnityEngine.Object[] FindObjectsOfType(System.Type tp)
        {
            if (tp == null)
            {
                return(ArrayUtil.Empty <UnityEngine.Object>());
            }

            if (tp.IsInterface)
            {
                var map = GetInterfaceComponentMap(tp);
                using (var lst = TempCollection.GetList <UnityEngine.Object>())
                {
                    foreach (var ctp in map)
                    {
                        lst.AddRange(UnityEngine.Object.FindObjectsOfType(ctp));
                    }
                    return(lst.ToArray());
                }
            }
            else
            {
                return(UnityEngine.Object.FindObjectsOfType(tp));
            }
        }
Пример #3
0
        /// <summary>
        /// Call once per frame
        /// </summary>
        private void Update()
        {
            var e = _dict.GetEnumerator();

            while (e.MoveNext())
            {
                if (e.Current.Value.Active)
                {
                    e.Current.Value.Update();
                }
            }

            if (_sequences.Count > 0)
            {
                using (var set = TempCollection.GetSet <ISequence>())
                {
                    var e2 = _sequences.GetEnumerator();
                    while (e2.MoveNext())
                    {
                        if (e2.Current.Update())
                        {
                            set.Add(e2.Current);
                        }
                    }

                    if (set.Count > 0)
                    {
                        e2 = set.GetEnumerator();
                        while (e2.MoveNext())
                        {
                            _sequences.Remove(e2.Current);
                        }
                    }
                }
            }
        }
Пример #4
0
        public override int SenseAll <T>(ICollection <T> lst, System.Func <T, bool> p = null)
        {
            if (lst == null)
            {
                throw new System.ArgumentNullException("lst");
            }
            if (lst.IsReadOnly)
            {
                throw new System.ArgumentException("List to fill can not be read-only.", "lst");
            }
            if (_sensors == null)
            {
                this.SyncChildSensors();
            }
            if (_sensors.Length == 0)
            {
                return(0);
            }

            if (_mustBeVisibleByAll && _sensors.Length > 1)
            {
                using (var set = com.spacepuppy.Collections.TempCollection.GetSet <T>())
                {
                    int resultCnt = 0;
                    _sensors[0].SenseAll <T>(set, p);
                    var e = set.GetEnumerator();
                    while (e.MoveNext())
                    {
                        int cnt = 1;
                        for (int i = 1; i < _sensors.Length; i++)
                        {
                            if (!_sensors[i].Visible(e.Current))
                            {
                                cnt++;
                            }
                        }
                        if (cnt == _sensors.Length)
                        {
                            resultCnt++;
                            lst.Add(e.Current);
                        }
                    }
                    return(resultCnt);
                }
            }
            else
            {
                /*
                 * //todo - make distinct
                 * int cnt = 0;
                 * for (int i = 0; i < _sensors.Length; i++)
                 * {
                 *  cnt += _sensors[i].SenseAll<T>(lst, p);
                 * }
                 * return cnt;
                 */
                using (var set = TempCollection.GetSet <T>())
                {
                    for (int i = 0; i < _sensors.Length; i++)
                    {
                        _sensors[i].SenseAll <T>(set, p);
                    }

                    var e = set.GetEnumerator();
                    while (e.MoveNext())
                    {
                        lst.Add(e.Current);
                    }
                    return(set.Count);
                }
            }
        }
 public bool Add(T Obj)
 {
     TempCollection.Add(Obj);
     return(true);
 }
Пример #6
0
        public static string ReflectedPropertyAndCustomTweenAccessorFieldByType(Rect position, GUIContent label, System.Type targType, string selectedMemberName, DynamicMemberAccess access, out System.Type propType)
        {
            if (targType != null)
            {
                var members   = DynamicUtil.GetEasilySerializedMembersFromType(targType, System.Reflection.MemberTypes.Field | System.Reflection.MemberTypes.Property, access).ToArray();
                var accessors = CustomTweenMemberAccessorFactory.GetCustomAccessorIds(targType, (d) => VariantReference.AcceptableType(d.MemberType));
                System.Array.Sort(accessors);

                using (var entries = TempCollection.GetList <GUIContent>(members.Length))
                {
                    int index = -1;
                    for (int i = 0; i < members.Length; i++)
                    {
                        var m = members[i];
                        if ((DynamicUtil.GetMemberAccessLevel(m) & DynamicMemberAccess.Write) != 0)
                        {
                            entries.Add(EditorHelper.TempContent(string.Format("{0} ({1})", m.Name, DynamicUtil.GetReturnType(m).Name)));
                        }
                        else
                        {
                            entries.Add(EditorHelper.TempContent(string.Format("{0} (readonly - {1})", m.Name, DynamicUtil.GetReturnType(m).Name)));
                        }

                        if (index < 0 && m.Name == selectedMemberName)
                        {
                            //index = i;
                            index = entries.Count - 1;
                        }
                    }

                    for (int i = 0; i < accessors.Length; i++)
                    {
                        entries.Add(EditorHelper.TempContent(accessors[i]));
                        if (index < 0 && accessors[i] == selectedMemberName)
                        {
                            index = entries.Count - 1;
                        }
                    }


                    index = EditorGUI.Popup(position, label, index, entries.ToArray());

                    if (index < 0)
                    {
                        propType = null;
                        return(null);
                    }
                    else if (index < members.Length)
                    {
                        propType = DynamicUtil.GetReturnType(members[index]);
                        return(members[index].Name);
                    }
                    else
                    {
                        var nm = accessors[index - members.Length];
                        CustomTweenMemberAccessorFactory.CustomAccessorData info;
                        if (CustomTweenMemberAccessorFactory.TryGetMemberAccessorInfoByType(targType, nm, out info))
                        {
                            propType = info.MemberType;
                            if (VariantReference.AcceptableType(propType))
                            {
                                return(nm);
                            }
                        }
                    }

                    propType = null;
                    return(null);
                }
            }
            else
            {
                propType = null;
                EditorGUI.Popup(position, label, -1, new GUIContent[0]);
                return(null);
            }
        }
        public static Rect DrawTimeSupplier(Rect position, SerializedProperty property, float desiredWidth, string[] availableNames)
        {
            if (position.width <= 0f)
            {
                return(position);
            }

            var r = new Rect(position.xMin, position.yMin, Mathf.Min(position.width, desiredWidth), position.height);

            var tsTypeProp = property.FindPropertyRelative(PROP_TIMESUPPLIERTYPE);
            var tsNameProp = property.FindPropertyRelative(PROP_TIMESUPPLIERNAME);

            int index = -1;

            using (var lst = TempCollection.GetList <string>())
            {
                lst.Add("Normal");
                lst.Add("Real");
                lst.Add("Smooth");

                foreach (var nm in CustomTimeLayersData.Layers)
                {
                    if (!lst.Contains(nm))
                    {
                        lst.Add(nm);
                    }
                }

                if (availableNames != null)
                {
                    foreach (var nm in availableNames)
                    {
                        if (!lst.Contains(nm))
                        {
                            lst.Add(nm);
                        }
                    }
                }

                var e = tsTypeProp.GetEnumValue <DeltaTimeType>();
                if (e == DeltaTimeType.Custom)
                {
                    index = lst.IndexOf(tsNameProp.stringValue);
                    if (index < 0)
                    {
                        tsTypeProp.SetEnumValue(DeltaTimeType.Normal);
                        tsNameProp.stringValue = null;
                        index = 0;
                    }
                }
                else
                {
                    index = (int)e;
                }

                var cache = SPGUI.DisableIfPlaying();
                EditorGUI.BeginChangeCheck();
                index = Mathf.Max(EditorGUI.Popup(position, index, lst.ToArray()), 0);
                if (EditorGUI.EndChangeCheck())
                {
                    if (index < 3)
                    {
                        tsTypeProp.SetEnumValue((DeltaTimeType)index);
                        tsNameProp.stringValue = null;
                    }
                    else
                    {
                        tsTypeProp.SetEnumValue(DeltaTimeType.Custom);
                        tsNameProp.stringValue = lst[index];
                    }
                }
                cache.Reset();
            }

            return(new Rect(r.xMax, position.yMin, Mathf.Max(position.width - r.width, 0f), position.height));
        }
Пример #8
0
        public static T[] GetAllFromSource <T>(object obj, bool includeChildren = false) where T : class
        {
            if (obj == null)
            {
                return(ArrayUtil.Empty <T>());
            }

            using (var set = TempCollection.GetSet <T>())
            {
                if (obj is T)
                {
                    set.Add(obj as T);
                }
                if (obj is IComponent)
                {
                    var c = (obj as IComponent).component;
                    if (c is T)
                    {
                        set.Add(c as T);
                    }
                }

                var go = GameObjectUtil.GetGameObjectFromSource(obj);
                if (go is T)
                {
                    set.Add(go as T);
                }

                //if (go != null && ComponentUtil.IsAcceptableComponentType(typeof(T))) go.GetComponentsAlt<T>(set);
                if (go != null)
                {
                    var tp = typeof(T);
                    if (typeof(SPEntity).IsAssignableFrom(tp))
                    {
                        var entity = SPEntity.Pool.GetFromSource(tp, go) as T;
                        if (entity != null)
                        {
                            set.Add(entity);
                        }
                    }
                    else if (typeof(UnityEngine.GameObject).IsAssignableFrom(tp))
                    {
                        if (includeChildren)
                        {
                            using (var lst = TempCollection.GetList <UnityEngine.Transform>())
                            {
                                go.GetComponentsInChildren <UnityEngine.Transform>(lst);

                                var e = lst.GetEnumerator();
                                while (e.MoveNext())
                                {
                                    set.Add(e.Current.gameObject as T);
                                }
                            }
                        }
                    }
                    if (ComponentUtil.IsAcceptableComponentType(tp))
                    {
                        if (includeChildren)
                        {
                            go.GetChildComponents <T>(set, true);
                        }
                        else
                        {
                            go.GetComponents <T>(set);
                        }
                    }
                }

                return(set.Count > 0 ? set.ToArray() : ArrayUtil.Empty <T>());
            }
        }
        private System.Collections.IEnumerable ReduceTargets(object triggerArg)
        {
            switch (_find)
            {
            case FindCommand.Direct:
            {
                object obj = (_configured) ? _target : triggerArg;
                if (ObjUtil.IsNullOrDestroyed(obj))
                {
                    yield break;
                }
                switch (_resolveBy)
                {
                case ResolveByCommand.Nothing:
                    yield return(obj);

                    break;

                case ResolveByCommand.WithTag:
                {
                    var go = GameObjectUtil.GetGameObjectFromSource(obj);
                    if (go.HasTag(_queryString))
                    {
                        yield return(obj);
                    }
                }
                break;

                case ResolveByCommand.WithName:
                {
                    var go = GameObjectUtil.GetGameObjectFromSource(obj);
                    if (go.CompareName(_queryString))
                    {
                        yield return(obj);
                    }
                }
                break;

                case ResolveByCommand.WithType:
                {
                    var o = ObjUtil.GetAsFromSource(TypeUtil.FindType(_queryString), GameObjectUtil.GetGameObjectFromSource(obj));
                    if (o != null)
                    {
                        yield return(o);
                    }
                }
                break;
                }
            }
            break;

            case FindCommand.FindParent:
            {
                Transform trans = GameObjectUtil.GetTransformFromSource((_configured) ? _target : triggerArg);
                if (trans == null)
                {
                    yield break;
                }
                switch (_resolveBy)
                {
                case ResolveByCommand.Nothing:
                {
                    var t = trans.parent;
                    if (t != null)
                    {
                        yield return(t);
                    }
                }
                break;

                case ResolveByCommand.WithTag:
                {
                    foreach (var p in GameObjectUtil.GetParents(trans))
                    {
                        if (p.HasTag(_queryString))
                        {
                            yield return(p);
                        }
                    }
                }
                break;

                case ResolveByCommand.WithName:
                {
                    foreach (var p in GameObjectUtil.GetParents(trans))
                    {
                        if (p.CompareName(_queryString))
                        {
                            yield return(p);
                        }
                    }
                }
                break;

                case ResolveByCommand.WithType:
                {
                    var tp = TypeUtil.FindType(_queryString);
                    foreach (var p in GameObjectUtil.GetParents(trans))
                    {
                        var o = ObjUtil.GetAsFromSource(tp, p);
                        if (o != null)
                        {
                            yield return(o);
                        }
                    }
                }
                break;
                }
            }
            break;

            case FindCommand.FindInChildren:
            {
                Transform trans = GameObjectUtil.GetTransformFromSource((_configured) ? _target : triggerArg);
                if (trans == null)
                {
                    yield break;
                }
                switch (_resolveBy)
                {
                case ResolveByCommand.Nothing:
                    if (trans.childCount > 0)
                    {
                        yield return(trans.GetChild(0));
                    }
                    break;

                case ResolveByCommand.WithTag:
                    if (trans.childCount > 0)
                    {
                        using (var lst = TempCollection.GetList <Transform>())
                        {
                            GameObjectUtil.GetAllChildren(trans, lst);
                            for (int i = 0; i < lst.Count; i++)
                            {
                                if (lst[i].HasTag(_queryString))
                                {
                                    yield return(lst[i]);
                                }
                            }
                        }
                    }
                    break;

                case ResolveByCommand.WithName:
                    if (trans.childCount > 0)
                    {
                        using (var lst = TempCollection.GetList <Transform>())
                        {
                            GameObjectUtil.GetAllChildren(trans, lst);
                            for (int i = 0; i < lst.Count; i++)
                            {
                                if (lst[i].CompareName(_queryString))
                                {
                                    yield return(lst[i]);
                                }
                            }
                        }
                    }
                    break;

                case ResolveByCommand.WithType:
                    if (trans.childCount > 0)
                    {
                        var tp = TypeUtil.FindType(_queryString);
                        using (var lst = TempCollection.GetList <Transform>())
                        {
                            GameObjectUtil.GetAllChildren(trans, lst);
                            for (int i = 0; i < lst.Count; i++)
                            {
                                var o = ObjUtil.GetAsFromSource(tp, lst[i]);
                                if (o != null)
                                {
                                    yield return(o);
                                }
                            }
                        }
                    }
                    break;
                }
            }
            break;

            case FindCommand.FindInEntity:
            {
                GameObject entity = GameObjectUtil.GetRootFromSource((_configured) ? _target : triggerArg);
                if (entity == null)
                {
                    yield break;
                }
                ;

                switch (_resolveBy)
                {
                case ResolveByCommand.Nothing:
                    yield return(entity);

                    break;

                case ResolveByCommand.WithTag:
                {
                    foreach (var o in entity.FindAllWithMultiTag(_queryString))
                    {
                        yield return(o);
                    }
                }
                break;

                case ResolveByCommand.WithName:
                {
                    foreach (var o in GameObjectUtil.FindAllByName(entity.transform, _queryString))
                    {
                        yield return(o);
                    }
                }
                break;

                case ResolveByCommand.WithType:
                {
                    var tp = TypeUtil.FindType(_queryString);
                    using (var lst = TempCollection.GetList <Transform>())
                    {
                        GameObjectUtil.GetAllChildrenAndSelf(entity.transform, lst);
                        for (int i = 0; i < lst.Count; i++)
                        {
                            var o = ObjUtil.GetAsFromSource(tp, lst[i]);
                            if (o != null)
                            {
                                yield return(o);
                            }
                        }
                    }
                }
                break;
                }
            }
            break;

            case FindCommand.FindInScene:
            {
                switch (_resolveBy)
                {
                case ResolveByCommand.Nothing:
                {
                    var go = GameObjectUtil.GetGameObjectFromSource((_configured) ? _target : triggerArg);
                    if (go != null)
                    {
                        yield return(go);
                    }
                }
                break;

                case ResolveByCommand.WithTag:
                {
                    foreach (var o in GameObjectUtil.FindGameObjectsWithMultiTag(_queryString))
                    {
                        yield return(o);
                    }
                }
                break;

                case ResolveByCommand.WithName:
                {
                    foreach (var o in GameObjectUtil.FindAllByName(_queryString))
                    {
                        yield return(o);
                    }
                }
                break;

                case ResolveByCommand.WithType:
                {
                    foreach (var o in ObjUtil.FindAll(SearchBy.Type, _queryString))
                    {
                        yield return(o);
                    }
                }
                break;
                }
            }
            break;

            case FindCommand.FindEntityInScene:
            {
                switch (_resolveBy)
                {
                case ResolveByCommand.Nothing:
                {
                    var go = GameObjectUtil.GetGameObjectFromSource((_configured) ? _target : triggerArg);
                    if (go != null)
                    {
                        yield return(go);
                    }
                }
                break;

                case ResolveByCommand.WithTag:
                {
                    var e = SPEntity.Pool.GetEnumerator();
                    while (e.MoveNext())
                    {
                        if (e.Current.HasTag(_queryString))
                        {
                            yield return(e.Current);
                        }
                    }
                }
                break;

                case ResolveByCommand.WithName:
                {
                    var e = SPEntity.Pool.GetEnumerator();
                    while (e.MoveNext())
                    {
                        if (e.Current.CompareName(_queryString))
                        {
                            yield return(e.Current);
                        }
                    }
                }
                break;

                case ResolveByCommand.WithType:
                {
                    var e  = SPEntity.Pool.GetEnumerator();
                    var tp = TypeUtil.FindType(_queryString);
                    while (e.MoveNext())
                    {
                        var o = e.Current.GetComponent(tp);
                        if (o != null)
                        {
                            yield return(o);
                        }
                    }
                }
                break;
                }
            }
            break;
            }
        }
        void IUpdateable.Update()
        {
            //stop if we shouldn't be running
            if (!_activelyScanning || !this.isActiveAndEnabled || _intersectingObjects.Count == 0)
            {
                this.StopUpdate();
                return;
            }

            //check timer
            if (_activeScanInterval > 0f)
            {
                _timer += Time.unscaledDeltaTime;
                if (_timer < _activeScanInterval)
                {
                    return;
                }
            }
            _timer = 0f;

            //perform scan of current objects
            bool containsActiveObjects = _activeObjects.Count > 0;

            using (var toRemove = TempCollection.GetSet <GameObject>())
            {
                var e = _intersectingObjects.GetEnumerator();
                while (e.MoveNext())
                {
                    if (!ObjUtil.IsObjectAlive(e.Current) || !e.Current.activeInHierarchy)
                    {
                        _activeObjects.Remove(e.Current);
                        toRemove.Add(e.Current);
                        continue;
                    }

                    if (_mask.Value != null)
                    {
                        if (_mask.Value.Intersects(e.Current))
                        {
                            _activeObjects.Add(e.Current);
                        }
                        else
                        {
                            _activeObjects.Remove(e.Current);
                        }
                    }
                }

                if (toRemove.Count > 0)
                {
                    e = toRemove.GetEnumerator();
                    while (e.MoveNext())
                    {
                        _intersectingObjects.Remove(e.Current);
                    }
                }
            }

            //wrap up by firing of appropriate events
            if (_activeObjects.Count == 0 && _intersectingObjects.Count == 0)
            {
                this.StopUpdate();
            }

            if (containsActiveObjects)
            {
                if (_activeObjects.Count == 0)
                {
                    _onTriggerLastExited.ActivateTrigger(this, null);
                }
            }
            else
            {
                if (_activeObjects.Count > 0)
                {
                    _onTriggerOccupied.ActivateTrigger(this, null);
                }
            }
        }
Пример #11
0
 public TempCollection FetchByID(object TempID)
 {
     TempCollection coll = new TempCollection().Where("tempID", TempID).Load();
     return coll;
 }
        private void ApplyDefaultAsList(SerializedProperty property, System.Type elementType, bool bUseEntity)
        {
            if (property.arraySize != 0)
            {
                return;
            }

            if (TypeUtil.IsType(elementType, typeof(Component)))
            {
                using (var lst = TempCollection.GetList <Component>())
                {
                    var targ = GameObjectUtil.GetGameObjectFromSource(property.serializedObject.targetObject);
                    if (targ != null)
                    {
                        if (bUseEntity)
                        {
                            targ.FindComponents(elementType, lst, true);
                        }
                        else
                        {
                            targ.GetComponents(elementType, lst);
                        }
                    }

                    property.arraySize = lst.Count;
                    for (int i = 0; i < lst.Count; i++)
                    {
                        property.GetArrayElementAtIndex(i).objectReferenceValue = lst[i];
                    }
                    property.serializedObject.ApplyModifiedProperties();
                }
            }
            else if (TypeUtil.IsType(elementType, typeof(GameObject)))
            {
                var targ = GameObjectUtil.GetGameObjectFromSource(property.serializedObject.targetObject);
                if (targ != null)
                {
                    if (bUseEntity)
                    {
                        property.arraySize = 1;
                        property.GetArrayElementAtIndex(0).objectReferenceValue = targ.FindRoot();
                    }
                    else
                    {
                        property.arraySize = 1;
                        property.GetArrayElementAtIndex(0).objectReferenceValue = targ;
                    }
                    property.serializedObject.ApplyModifiedProperties();
                }
            }
            else if (TypeUtil.IsType(elementType, typeof(UnityEngine.Object)))
            {
                property.arraySize = 1;
                var obj = property.serializedObject.targetObject;
                if (GameObjectUtil.IsGameObjectSource(obj))
                {
                    obj = GameObjectUtil.GetGameObjectFromSource(obj);
                }
                property.GetArrayElementAtIndex(0).objectReferenceValue = obj;
                property.serializedObject.ApplyModifiedProperties();
            }
        }
        public static SPEditorAddonDrawer[] GetDrawers(UnityEditor.SerializedObject target)
        {
            if (target == null)
            {
                return(ArrayUtil.Empty <SPEditorAddonDrawer>());
            }

            Type compType = typeof(UnityEngine.Component);
            Type targType = target.GetTargetType();

            if (!compType.IsAssignableFrom(targType))
            {
                return(ArrayUtil.Empty <SPEditorAddonDrawer>());
            }
            if (_inspectedTypeToAddonDrawerType == null)
            {
                BuildAddonDrawerTypeTable();
            }
            if (_inspectedTypeToAddonDrawerType.Count == 0)
            {
                return(ArrayUtil.Empty <SPEditorAddonDrawer>());
            }

            using (var lst = TempCollection.GetList <SPEditorAddonDrawer>())
            {
                var tp = targType;
                while (tp != null && compType.IsAssignableFrom(tp))
                {
                    object v;
                    if (_inspectedTypeToAddonDrawerType.TryGetValue(tp, out v))
                    {
                        if (v is List <DrawerInfo> )
                        {
                            foreach (var info in (v as List <DrawerInfo>))
                            {
                                var d = info.CreateDrawer(target);
                                if (d != null)
                                {
                                    lst.Add(d);
                                }
                            }
                        }
                        else if (v is DrawerInfo)
                        {
                            var d = (v as DrawerInfo).CreateDrawer(target);
                            if (d != null)
                            {
                                lst.Add(d);
                            }
                        }
                    }

                    tp = tp.BaseType;
                }

                foreach (var itp in targType.GetInterfaces())
                {
                    object v;
                    if (_inspectedTypeToAddonDrawerType.TryGetValue(itp, out v))
                    {
                        if (v is List <DrawerInfo> )
                        {
                            foreach (var info in (v as List <DrawerInfo>))
                            {
                                var d = info.CreateDrawer(target);
                                if (d != null)
                                {
                                    lst.Add(d);
                                }
                            }
                        }
                        else if (v is DrawerInfo)
                        {
                            var d = (v as DrawerInfo).CreateDrawer(target);
                            if (d != null)
                            {
                                lst.Add(d);
                            }
                        }
                    }
                }

                return(lst.ToArray());
            }
        }
        void IUpdateable.Update()
        {
            if (_currentToken == null)
            {
                GameLoopEntry.UpdatePump.Remove(this);
                return;
            }

            TempHashSet <AudibleSensor> activeSet = null;

            if (_activeSensors.Count > 0)
            {
                activeSet = TempCollection.GetSet(_activeSensors);
            }

            var   pos = this.transform.position;
            float d, r;

            var e = AudibleSensor.Pool.GetEnumerator();

            while (e.MoveNext())
            {
                var sensor = e.Current;
                if (_activeSensors.Contains(sensor) || sensor.Ignores(this))
                {
                    continue;
                }

                if (_omniPresent)
                {
                    _activeSensors.Add(sensor);
                    sensor.SignalEnterSiren(this);
                }
                else
                {
                    d = (sensor.transform.position - pos).sqrMagnitude;
                    r = (sensor.Range + _range);
                    if (d < r * r)
                    {
                        _activeSensors.Add(sensor);
                        sensor.SignalEnterSiren(this);
                    }
                }
            }

            if (activeSet != null)
            {
                var e2 = activeSet.GetEnumerator();
                while (e2.MoveNext())
                {
                    var sensor = e.Current;

                    if (!_omniPresent)
                    {
                        d = (sensor.transform.position - pos).sqrMagnitude;
                        r = (sensor.Range + _range);
                        if (d < r * r)
                        {
                            sensor.SignalSirenStay(this);
                        }
                        else
                        {
                            _activeSensors.Remove(sensor);
                            sensor.SignalExitSiren(this);
                        }
                    }
                }

                activeSet.Dispose();
            }
        }
Пример #15
0
        void IUpdateable.Update()
        {
            _inUpdate = true;
            if (!_state.IsPlaying)
            {
                //close them all down
                this.CloseOutAllEventCallbacks();
            }
            else
            {
                if (_timeoutInfos != null && _timeoutInfos.Count > 0)
                {
                    var e = _timeoutInfos.GetEnumerator();
                    while (e.MoveNext())
                    {
                        e.Current.timeout -= e.Current.supplier.Delta;
                        if (e.Current.timeout <= 0f)
                        {
                            var a = e.Current.callback;
                            e.Current.callback = null;
                            if (_toAddOrRemove == null)
                            {
                                _toAddOrRemove = TempCollection.GetList <CallbackInfo>();
                            }
                            _toAddOrRemove.Add(e.Current);

                            try
                            {
                                a(_state);
                            }
                            catch (System.Exception ex)
                            {
                                Debug.LogException(ex);
                            }
                        }
                    }
                }
            }
            _inUpdate = false;

            //check if any timeouts wanted to get registered while calling update
            if (_toAddOrRemove != null)
            {
                var e = _toAddOrRemove.GetEnumerator();
                while (e.MoveNext())
                {
                    if (e.Current.callback == null)
                    {
                        //I set it null in the loop above to flag it as 'remove' rather than 'add'
                        _timeoutInfos.Remove(e.Current);
                        _pool.Release(e.Current);
                    }
                    else
                    {
                        _timeoutInfos.Add(e.Current);
                    }
                }
                _toAddOrRemove.Dispose();
                _toAddOrRemove = null;
            }


            //stop us
            if (!this.ContainsWaitHandles())
            {
                GameLoop.UpdatePump.Remove(this);
            }
        }
        public static string ReflectedPropertyAndCustomTweenAccessorField(Rect position, GUIContent label, object targObj, string selectedMemberName, DynamicMemberAccess access, out System.Type propType)
        {
            if (targObj != null)
            {
                var members   = DynamicUtil.GetEasilySerializedMembers(targObj, System.Reflection.MemberTypes.Field | System.Reflection.MemberTypes.Property, access).ToArray();
                var accessors = CustomTweenMemberAccessorFactory.GetCustomAccessorIds(targObj.GetType());
                System.Array.Sort(accessors);

                using (var entries = TempCollection.GetList <GUIContent>(members.Length))
                {
                    int index = -1;
                    for (int i = 0; i < members.Length; i++)
                    {
                        var m = members[i];
                        if ((DynamicUtil.GetMemberAccessLevel(m) & DynamicMemberAccess.Write) != 0)
                        {
                            entries.Add(EditorHelper.TempContent(string.Format("{0} ({1}) -> {2}", m.Name, DynamicUtil.GetReturnType(m).Name, DynamicUtil.GetValueWithMember(m, targObj))));
                        }
                        else
                        {
                            entries.Add(EditorHelper.TempContent(string.Format("{0} (readonly - {1}) -> {2}", m.Name, DynamicUtil.GetReturnType(m).Name, DynamicUtil.GetValueWithMember(m, targObj))));
                        }

                        if (index < 0 && m.Name == selectedMemberName)
                        {
                            //index = i;
                            index = entries.Count - 1;
                        }
                    }

                    for (int i = 0; i < accessors.Length; i++)
                    {
                        entries.Add(EditorHelper.TempContent(accessors[i]));
                        if (index < 0 && accessors[i] == selectedMemberName)
                        {
                            index = entries.Count - 1;
                        }
                    }


                    index = EditorGUI.Popup(position, label, index, entries.ToArray());
                    //selectedMember = (index >= 0) ? members[index] : null;
                    //return (selectedMember != null) ? selectedMember.Name : null;

                    if (index < 0)
                    {
                        propType = null;
                        return(null);
                    }
                    else if (index < members.Length)
                    {
                        propType = DynamicUtil.GetReturnType(members[index]);
                        return(members[index].Name);
                    }
                    else
                    {
                        var nm = accessors[index - members.Length];
                        ITweenMemberAccessor acc;
                        if (CustomTweenMemberAccessorFactory.TryGetMemberAccessor(targObj, nm, out acc))
                        {
                            propType = acc.GetMemberType();
                            if (VariantReference.AcceptableType(propType))
                            {
                                return(nm);
                            }
                        }
                    }

                    propType = null;
                    return(null);
                }
            }
            else
            {
                propType = null;
                EditorGUI.Popup(position, label, -1, new GUIContent[0]);
                return(null);
            }
        }
Пример #17
0
 public TempCollection FetchByQuery(Query qry)
 {
     TempCollection coll = new TempCollection();
     coll.LoadAndCloseReader(qry.ExecuteReader()); 
     return coll;
 }
        private object ReduceTarget(object triggerArg)
        {
            var targ = _target;

            if (targ is IProxy)
            {
                targ = (targ as IProxy).GetTarget(triggerArg) as UnityEngine.Object;
            }

            switch (_find)
            {
            case FindCommand.Direct:
            {
                object obj = (_configured) ? targ : triggerArg;
                if (ObjUtil.IsNullOrDestroyed(obj))
                {
                    return(null);
                }
                switch (_resolveBy)
                {
                case ResolveByCommand.Nothing:
                    return(obj);

                case ResolveByCommand.WithTag:
                    return(GameObjectUtil.GetGameObjectFromSource(obj).HasTag(_queryString) ? obj : null);

                case ResolveByCommand.WithName:
                    return(GameObjectUtil.GetGameObjectFromSource(obj).CompareName(_queryString) ? obj : null);

                case ResolveByCommand.WithType:
                    return(ObjUtil.GetAsFromSource(TypeUtil.FindType(_queryString), GameObjectUtil.GetGameObjectFromSource(obj)) != null ? obj : null);
                }
            }
            break;

            case FindCommand.FindParent:
            {
                Transform trans = GameObjectUtil.GetTransformFromSource((_configured) ? targ : triggerArg);
                if (trans == null)
                {
                    return(null);
                }
                switch (_resolveBy)
                {
                case ResolveByCommand.Nothing:
                    return(trans.parent);

                case ResolveByCommand.WithTag:
                    return(trans.FindParentWithTag(_queryString));

                case ResolveByCommand.WithName:
                    return(trans.FindParentWithName(_queryString));

                case ResolveByCommand.WithType:
                {
                    var tp = TypeUtil.FindType(_queryString);
                    foreach (var p in GameObjectUtil.GetParents(trans))
                    {
                        var o = ObjUtil.GetAsFromSource(tp, p);
                        if (o != null)
                        {
                            return(o);
                        }
                    }
                    return(null);
                }
                }
            }
            break;

            case FindCommand.FindInChildren:
            {
                Transform trans = GameObjectUtil.GetTransformFromSource((_configured) ? targ : triggerArg);
                if (trans == null)
                {
                    return(null);
                }
                switch (_resolveBy)
                {
                case ResolveByCommand.Nothing:
                    return((trans.childCount > 0) ? trans.GetChild(0) : null);

                case ResolveByCommand.WithTag:
                    if (trans.childCount > 0)
                    {
                        using (var lst = TempCollection.GetList <Transform>())
                        {
                            GameObjectUtil.GetAllChildren(trans, lst);
                            for (int i = 0; i < lst.Count; i++)
                            {
                                if (lst[i].HasTag(_queryString))
                                {
                                    return(lst[i]);
                                }
                            }
                        }
                    }
                    break;

                case ResolveByCommand.WithName:
                    if (trans.childCount > 0)
                    {
                        return(trans.FindByName(_queryString));
                    }
                    break;

                case ResolveByCommand.WithType:
                    if (trans.childCount > 0)
                    {
                        var tp = TypeUtil.FindType(_queryString);
                        using (var lst = TempCollection.GetList <Transform>())
                        {
                            GameObjectUtil.GetAllChildren(trans, lst);
                            for (int i = 0; i < lst.Count; i++)
                            {
                                var o = ObjUtil.GetAsFromSource(tp, lst[i]);
                                if (o != null)
                                {
                                    return(o);
                                }
                            }
                        }
                    }
                    break;
                }
            }
            break;

            case FindCommand.FindInEntity:
            {
                GameObject entity = GameObjectUtil.GetRootFromSource((_configured) ? targ : triggerArg);
                if (entity == null)
                {
                    return(null);
                }

                switch (_resolveBy)
                {
                case ResolveByCommand.Nothing:
                    return(entity);

                case ResolveByCommand.WithTag:
                    return(entity.FindWithMultiTag(_queryString));

                case ResolveByCommand.WithName:
                    return(entity.FindByName(_queryString));

                case ResolveByCommand.WithType:
                {
                    var tp = TypeUtil.FindType(_queryString);
                    foreach (var t in GameObjectUtil.GetAllChildrenAndSelf(entity))
                    {
                        var o = ObjUtil.GetAsFromSource(tp, t);
                        if (o != null)
                        {
                            return(o);
                        }
                    }
                    return(null);
                }
                }
            }
            break;

            case FindCommand.FindInScene:
            {
                switch (_resolveBy)
                {
                case ResolveByCommand.Nothing:
                    return(GameObjectUtil.GetGameObjectFromSource((_configured) ? targ : triggerArg));

                case ResolveByCommand.WithTag:
                    return(GameObjectUtil.FindWithMultiTag(_queryString));

                case ResolveByCommand.WithName:
                    return(GameObject.Find(_queryString));

                case ResolveByCommand.WithType:
                    return(ObjUtil.Find(SearchBy.Type, _queryString));
                }
            }
            break;

            case FindCommand.FindEntityInScene:
            {
                switch (_resolveBy)
                {
                case ResolveByCommand.Nothing:
                    return(GameObjectUtil.GetGameObjectFromSource((_configured) ? targ : triggerArg));

                case ResolveByCommand.WithTag:
                {
                    var e = SPEntity.Pool.GetEnumerator();
                    while (e.MoveNext())
                    {
                        if (e.Current.HasTag(_queryString))
                        {
                            return(e.Current);
                        }
                    }
                }
                break;

                case ResolveByCommand.WithName:
                {
                    var e = SPEntity.Pool.GetEnumerator();
                    while (e.MoveNext())
                    {
                        if (e.Current.CompareName(_queryString))
                        {
                            return(e.Current);
                        }
                    }
                }
                break;

                case ResolveByCommand.WithType:
                {
                    var e  = SPEntity.Pool.GetEnumerator();
                    var tp = TypeUtil.FindType(_queryString);
                    while (e.MoveNext())
                    {
                        var o = e.Current.GetComponentInChildren(tp);
                        if (o != null)
                        {
                            return(o);
                        }
                    }
                }
                break;
                }
            }
            break;
            }

            return(null);
        }
        private static void ApplyDefaultAsList(SerializedProperty property, System.Type elementType, string name, bool bUseEntity)
        {
            if (elementType == null)
            {
                return;
            }
            if (property.arraySize != 0)
            {
                return;
            }

            var targ = GameObjectUtil.GetGameObjectFromSource(property.serializedObject.targetObject);

            if (targ == null)
            {
                return;
            }
            if (bUseEntity)
            {
                targ = targ.FindRoot();
            }

            if (TypeUtil.IsType(elementType, typeof(VariantReference)))
            {
                var arr = targ.transform.FindAllByName(name);
                if (arr.Length > 0)
                {
                    property.arraySize = arr.Length;
                    property.serializedObject.ApplyModifiedProperties();
                    for (int i = 0; i < arr.Length; i++)
                    {
                        var variant = EditorHelper.GetTargetObjectOfProperty(property.GetArrayElementAtIndex(i)) as VariantReference;
                        if (variant != null && variant.Value == null && variant.ValueType == VariantType.GameObject)
                        {
                            variant.GameObjectValue = arr[i].gameObject;
                        }
                    }
                    property.serializedObject.Update();
                }
            }
            else
            {
                if (ComponentUtil.IsAcceptableComponentType(elementType))
                {
                    using (var lst = TempCollection.GetList <Component>())
                    {
                        foreach (var child in targ.transform.FindAllByName(name))
                        {
                            child.GetComponents(elementType, lst);
                            if (lst.Count > 0)
                            {
                                int low = property.arraySize;
                                property.arraySize += lst.Count;
                                for (int i = 0; i < lst.Count; i++)
                                {
                                    property.GetArrayElementAtIndex(low + i).objectReferenceValue = lst[i];
                                }
                            }
                            lst.Clear();
                        }
                    }
                }
                else if (TypeUtil.IsType(elementType, typeof(GameObject)))
                {
                    var arr = targ.transform.FindAllByName(name);
                    if (arr.Length > 0)
                    {
                        property.arraySize = arr.Length;
                        for (int i = 0; i < arr.Length; i++)
                        {
                            property.GetArrayElementAtIndex(i).objectReferenceValue = arr[i].gameObject;
                        }
                        property.serializedObject.ApplyModifiedProperties();
                    }
                }
            }
        }
        private void DealWithDisable(MonoBehaviour component)
        {
            using (var lst = TempCollection.GetList <RadicalCoroutine>())
            {
                var e = _routines.GetEnumerator();
                while (e.MoveNext())
                {
                    if (e.Current.Operator == component)
                    {
                        lst.Add(e.Current);
                    }
                }

                if (lst.Count > 0)
                {
                    RadicalCoroutine routine;
                    if (this.gameObject.activeInHierarchy)
                    {
                        for (int i = 0; i < lst.Count; i++)
                        {
                            routine = lst[i];
                            if (routine.DisableMode.HasFlag(RadicalCoroutineDisableMode.CancelOnDisable))
                            {
                                routine.Cancel(true);
                                _routines.Remove(lst[i]);
                                lst.RemoveAt(i);
                                i--;
                            }
                            else if (routine.DisableMode.HasFlag(RadicalCoroutineDisableMode.StopOnDisable))
                            {
                                routine.Stop(true);
                                if (routine.Finished)
                                {
                                    _routines.Remove(lst[i]);
                                    lst.RemoveAt(i);
                                    i--;
                                }
                                else if (!routine.DisableMode.HasFlag(RadicalCoroutineDisableMode.Resumes))
                                {
                                    _routines.Remove(lst[i]);
                                    lst.RemoveAt(i);
                                    i--;
                                }
                            }
                        }
                    }
                    else
                    {
                        for (int i = 0; i < lst.Count; i++)
                        {
                            routine = lst[i];
                            if (routine.DisableMode.HasFlag(RadicalCoroutineDisableMode.StopOnDeactivate))
                            {
                                routine.Stop(true);
                                if (routine.Finished)
                                {
                                    _routines.Remove(lst[i]);
                                    lst.RemoveAt(i);
                                    i--;
                                }
                                else if (!routine.DisableMode.HasFlag(RadicalCoroutineDisableMode.Resumes))
                                {
                                    _routines.Remove(lst[i]);
                                    lst.RemoveAt(i);
                                    i--;
                                }
                            }
                            else
                            {
                                routine.Cancel(true);
                                _routines.Remove(lst[i]);
                                lst.RemoveAt(i);
                                i--;
                            }
                        }
                    }
                }
            }
        }
Пример #21
0
        protected override void OnSPInspectorGUI()
        {
            this.serializedObject.Update();
            var targ = this.target as ArmatureRig;

            this.DrawDefaultInspectorExcept("Joints");

            var cache = SPGUI.Disable();

            EditorGUILayout.FloatField("Mass", targ.CalculateMass());
            cache.Reset();

            EditorGUI.BeginChangeCheck();
            Rigidbody rootJoint = EditorGUILayout.ObjectField("Root Joint", targ.RootJoint, typeof(Rigidbody), true) as Rigidbody;

            if (EditorGUI.EndChangeCheck())
            {
                if (rootJoint != null)
                {
                    if (targ.JointCount == 0)
                    {
                        targ.SetJoints(new Rigidbody[] { rootJoint });
                    }
                    else
                    {
                        using (var lst = TempCollection.GetList <Rigidbody>(targ.Joints))
                        {
                            lst.Remove(rootJoint);
                            lst.Insert(0, rootJoint);
                            targ.SetJoints(lst);
                        }
                    }

                    this.serializedObject.Update();
                }
            }

            this.DrawPropertyField("Joints", true);

            //TODO - implement a button that allows removing and setting the bones of the rig

            EditorGUILayout.Separator();

            if (GUILayout.Button("Build Ragdoll Rig"))
            {
                //EditorApplication.ExecuteMenuItem("GameObject/Create Other/Ragdoll...");
                com.spacepuppyeditor.Base.SPCreateRagdollWizard.StartWizard();
            }

            if (GUILayout.Button("Generate Joint List"))
            {
                targ.ReloadJointList();
                targ.LoadJointListOnStart = false;
                this.serializedObject.Update();
            }

            bool bIsKinematic = false;

            if (targ.Joints.Count() > 0)
            {
                bIsKinematic = targ.Joints.First().isKinematic;
            }
            string msg = (bIsKinematic) ? "Set Joints Not Kinematic" : "Set Joints Kinematic";

            if (GUILayout.Button(msg))
            {
                targ.SetJointsKinematic(!bIsKinematic);
            }

            if (GUILayout.Button("Try Clear Ragdoll Rig"))
            {
                if (EditorUtility.DisplayDialog("WARNING!", "Are you sure you want to clear rig?", "Yes", "No"))
                {
                    //foreach (var t in targ.GetAllChildrenAndSelf())
                    //{
                    //    if (t.HasComponent<CharacterJoint>())
                    //    {
                    //        DestroyImmediate(t.GetComponent<CharacterJoint>());
                    //        DestroyImmediate(t.GetComponent<Collider>());
                    //        DestroyImmediate(t.GetComponent<Rigidbody>());
                    //    }
                    //}
                    targ.ReloadJointList();
                    foreach (var j in targ.Joints)
                    {
                        if (j.HasComponent <CharacterJoint>())
                        {
                            DestroyImmediate(j.GetComponent <CharacterJoint>());
                        }
                        DestroyImmediate(j.GetComponent <Collider>());
                        DestroyImmediate(j);
                    }
                    targ.SetJoints(null);
                    this.serializedObject.Update();
                }
            }

            if (GUILayout.Button("Clear Defined Joints"))
            {
                if (targ.Joints.Count() > 0)
                {
                    if (EditorUtility.DisplayDialog("WARNING!", "Are you sure you want to clear all defined joints?", "Yes", "No"))
                    {
                        foreach (var j in targ.Joints)
                        {
                            var go = j.gameObject;
                            DestroyImmediate(go.GetComponent <CharacterJoint>());
                            DestroyImmediate(go.GetComponent <Collider>());
                            DestroyImmediate(go.GetComponent <Rigidbody>());
                        }
                    }

                    targ.SetJoints(null);
                    this.serializedObject.Update();
                }
            }

            if (Application.isPlaying)
            {
                GUILayout.Space(10);

                if (!targ.Ragdolled)
                {
                    if (GUILayout.Button("Ragdoll..."))
                    {
                        targ.Ragdoll();
                    }
                }
                else
                {
                    if (GUILayout.Button("Undo Ragdoll..."))
                    {
                        targ.UndoRagdoll();
                    }
                }
            }
        }
Пример #22
0
        public static object[] GetAllFromSource(System.Type tp, object obj, bool includeChildren = false)
        {
            if (obj == null)
            {
                return(ArrayUtil.Empty <object>());
            }

            using (var set = TempCollection.GetSet <object>())
            {
                var otp = obj.GetType();
                if (TypeUtil.IsType(otp, tp))
                {
                    set.Add(obj);
                }
                if (obj is IComponent)
                {
                    var c = (obj as IComponent).component;
                    if (!object.ReferenceEquals(c, null) && TypeUtil.IsType(c.GetType(), tp))
                    {
                        set.Add(c);
                    }
                }

                var go = GameObjectUtil.GetGameObjectFromSource(obj);
                if (go != null)
                {
                    if (typeof(SPEntity).IsAssignableFrom(tp))
                    {
                        var entity = SPEntity.Pool.GetFromSource(tp, go);
                        if (entity != null)
                        {
                            set.Add(entity);
                        }
                    }
                    else if (typeof(UnityEngine.GameObject).IsAssignableFrom(tp))
                    {
                        if (includeChildren)
                        {
                            using (var lst = TempCollection.GetList <UnityEngine.Transform>())
                            {
                                go.GetComponentsInChildren <UnityEngine.Transform>(lst);

                                var e = lst.GetEnumerator();
                                while (e.MoveNext())
                                {
                                    set.Add(e.Current.gameObject);
                                }
                            }
                        }
                        else
                        {
                            set.Add(go);
                        }
                    }
                    else if (ComponentUtil.IsAcceptableComponentType(tp))
                    {
                        using (var lst = TempCollection.GetList <UnityEngine.Component>())
                        {
                            if (includeChildren)
                            {
                                ComponentUtil.GetChildComponents(go, tp, lst, true);
                            }
                            else
                            {
                                go.GetComponents(tp, lst);
                            }

                            var e = lst.GetEnumerator();
                            while (e.MoveNext())
                            {
                                set.Add(e.Current);
                            }
                        }
                    }
                }

                return(set.Count > 0 ? set.ToArray() : ArrayUtil.Empty <object>());
            }
        }
        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            //property.isExpanded = EditorGUI.Foldout(new Rect(position.xMin, position.yMin, 15f, EditorGUIUtility.singleLineHeight), property.isExpanded, GUIContent.none);
            position = EditorGUI.PrefixLabel(position, label);


            //START DRAW WITH NO INDENTS
            EditorHelper.SuppressIndentLevel();


            var r0 = new Rect(position.xMin, position.yMin, position.width / 2f, position.height);
            var r1 = new Rect(r0.xMax, r0.yMin, position.width - r0.width, r0.height);

            var matProp      = property.FindPropertyRelative(PROP_MATERIAL);
            var valTypeProp  = property.FindPropertyRelative(PROP_VALUETYPE);
            var memberProp   = property.FindPropertyRelative(PROP_VALUEMEMBER);
            var propNameProp = property.FindPropertyRelative(PROP_PROPERTYNAME);


            EditorGUI.BeginChangeCheck();
            matProp.objectReferenceValue = EditorGUI.ObjectField(r1, matProp.objectReferenceValue, typeof(UnityEngine.Object), true);
            if (EditorGUI.EndChangeCheck())
            {
                if (!MaterialUtil.IsMaterialSource(matProp.objectReferenceValue))
                {
                    var go = GameObjectUtil.GetGameObjectFromSource(matProp.objectReferenceValue);
                    matProp.objectReferenceValue = (go != null) ? go.GetComponent <Renderer>() : null;
                }
            }

            var mat = MaterialUtil.GetMaterialFromSource(matProp.objectReferenceValue);

            if (mat != null && mat.shader != null)
            {
                int cnt = ShaderUtil.GetPropertyCount(mat.shader);
                using (var infoLst = TempCollection.GetList <PropInfo>(cnt))
                    using (var contentLst = TempCollection.GetList <GUIContent>(cnt))
                    {
                        int index = -1;

                        for (int i = 0; i < cnt; i++)
                        {
                            var nm = ShaderUtil.GetPropertyName(mat.shader, i);
                            var tp = ShaderUtil.GetPropertyType(mat.shader, i);

                            switch (tp)
                            {
                            case ShaderUtil.ShaderPropertyType.Float:
                            {
                                if (propNameProp.stringValue == nm)
                                {
                                    index = infoLst.Count;
                                }
                                infoLst.Add(new PropInfo(nm, MaterialPropertyValueType.Float));
                                contentLst.Add(EditorHelper.TempContent(nm + " (float)"));
                            }
                            break;

                            case ShaderUtil.ShaderPropertyType.Range:
                            {
                                if (propNameProp.stringValue == nm)
                                {
                                    index = infoLst.Count;
                                }
                                infoLst.Add(new PropInfo(nm, MaterialPropertyValueType.Float));
                                var min = ShaderUtil.GetRangeLimits(mat.shader, i, 1);
                                var max = ShaderUtil.GetRangeLimits(mat.shader, i, 2);
                                contentLst.Add(EditorHelper.TempContent(string.Format("{0} (Range [{1}, {2}]])", nm, min, max)));
                            }
                            break;

                            case ShaderUtil.ShaderPropertyType.Color:
                            {
                                if (propNameProp.stringValue == nm && memberProp.GetEnumValue <MaterialPropertyValueTypeMember>() == MaterialPropertyValueTypeMember.None)
                                {
                                    index = infoLst.Count;
                                }
                                infoLst.Add(new PropInfo(nm, MaterialPropertyValueType.Color));
                                contentLst.Add(EditorHelper.TempContent(nm + " (color)"));

                                //sub members
                                if (propNameProp.stringValue == nm && memberProp.GetEnumValue <MaterialPropertyValueTypeMember>() == MaterialPropertyValueTypeMember.X)
                                {
                                    index = infoLst.Count;
                                }
                                infoLst.Add(new PropInfo(nm, MaterialPropertyValueType.Color, MaterialPropertyValueTypeMember.X));
                                contentLst.Add(EditorHelper.TempContent(nm + ".r (float)"));

                                if (propNameProp.stringValue == nm && memberProp.GetEnumValue <MaterialPropertyValueTypeMember>() == MaterialPropertyValueTypeMember.Y)
                                {
                                    index = infoLst.Count;
                                }
                                infoLst.Add(new PropInfo(nm, MaterialPropertyValueType.Color, MaterialPropertyValueTypeMember.Y));
                                contentLst.Add(EditorHelper.TempContent(nm + ".g (float)"));

                                if (propNameProp.stringValue == nm && memberProp.GetEnumValue <MaterialPropertyValueTypeMember>() == MaterialPropertyValueTypeMember.Z)
                                {
                                    index = infoLst.Count;
                                }
                                infoLst.Add(new PropInfo(nm, MaterialPropertyValueType.Color, MaterialPropertyValueTypeMember.Z));
                                contentLst.Add(EditorHelper.TempContent(nm + ".b (float)"));

                                if (propNameProp.stringValue == nm && memberProp.GetEnumValue <MaterialPropertyValueTypeMember>() == MaterialPropertyValueTypeMember.W)
                                {
                                    index = infoLst.Count;
                                }
                                infoLst.Add(new PropInfo(nm, MaterialPropertyValueType.Color, MaterialPropertyValueTypeMember.W));
                                contentLst.Add(EditorHelper.TempContent(nm + ".a (float)"));
                            }
                            break;

                            case ShaderUtil.ShaderPropertyType.Vector:
                            {
                                if (propNameProp.stringValue == nm && memberProp.GetEnumValue <MaterialPropertyValueTypeMember>() == MaterialPropertyValueTypeMember.None)
                                {
                                    index = infoLst.Count;
                                }
                                infoLst.Add(new PropInfo(nm, MaterialPropertyValueType.Vector));
                                contentLst.Add(EditorHelper.TempContent(nm + " (vector)"));

                                //sub members
                                if (propNameProp.stringValue == nm && memberProp.GetEnumValue <MaterialPropertyValueTypeMember>() == MaterialPropertyValueTypeMember.X)
                                {
                                    index = infoLst.Count;
                                }
                                infoLst.Add(new PropInfo(nm, MaterialPropertyValueType.Vector, MaterialPropertyValueTypeMember.X));
                                contentLst.Add(EditorHelper.TempContent(nm + ".x (float)"));

                                if (propNameProp.stringValue == nm && memberProp.GetEnumValue <MaterialPropertyValueTypeMember>() == MaterialPropertyValueTypeMember.Y)
                                {
                                    index = infoLst.Count;
                                }
                                infoLst.Add(new PropInfo(nm, MaterialPropertyValueType.Vector, MaterialPropertyValueTypeMember.Y));
                                contentLst.Add(EditorHelper.TempContent(nm + ".y (float)"));

                                if (propNameProp.stringValue == nm && memberProp.GetEnumValue <MaterialPropertyValueTypeMember>() == MaterialPropertyValueTypeMember.Z)
                                {
                                    index = infoLst.Count;
                                }
                                infoLst.Add(new PropInfo(nm, MaterialPropertyValueType.Vector, MaterialPropertyValueTypeMember.Z));
                                contentLst.Add(EditorHelper.TempContent(nm + ".z (float)"));

                                if (propNameProp.stringValue == nm && memberProp.GetEnumValue <MaterialPropertyValueTypeMember>() == MaterialPropertyValueTypeMember.W)
                                {
                                    index = infoLst.Count;
                                }
                                infoLst.Add(new PropInfo(nm, MaterialPropertyValueType.Vector, MaterialPropertyValueTypeMember.W));
                                contentLst.Add(EditorHelper.TempContent(nm + ".w (float)"));
                            }
                            break;
                            }
                        }

                        EditorGUI.BeginChangeCheck();
                        index = EditorGUI.Popup(r0, index, contentLst.ToArray());

                        if (EditorGUI.EndChangeCheck())
                        {
                            if (index < 0)
                            {
                                valTypeProp.SetEnumValue(MaterialPropertyValueType.Float);
                                memberProp.SetEnumValue(MaterialPropertyValueTypeMember.None);
                                propNameProp.stringValue = string.Empty;
                            }
                            else
                            {
                                var info = infoLst[index];
                                valTypeProp.SetEnumValue(info.ValueType);
                                memberProp.SetEnumValue(info.MemberType);
                                propNameProp.stringValue = info.Name;
                            }
                        }
                    }
            }


            //SET INDENT BACK
            EditorHelper.ResumeIndentLevel();
        }
        public static int OverlapCapsule(Vector3 point1, Vector3 point2, float radius, ICollection<Collider> results,
                                         int layerMask = Physics.AllLayers, QueryTriggerInteraction query = QueryTriggerInteraction.UseGlobal)
        {
            if (results == null) throw new System.ArgumentNullException("results");

            //note, HashSets are inherently unique collections... so no need to check if contains during second and third overlaps
            using (var tmpSet = TempCollection.GetSet<Collider>())
            {
                if (VectorUtil.FuzzyEquals(point1, point2))
                {
                    int cnt = Physics.OverlapSphereNonAlloc(point1, radius, _nonallocColliderBuffer, layerMask, query);
                    for (int i = 0; i < cnt; i++)
                    {
                        tmpSet.Add(_nonallocColliderBuffer[i]);
                        _nonallocColliderBuffer[i] = null;
                    }
                }
                else
                {
                    if (_nonallocColliderBuffer == null) _nonallocColliderBuffer = new Collider[MAX_BUFFER];
                    if (_nonallocRaycastBuffer == null) _nonallocRaycastBuffer = new RaycastHit[MAX_BUFFER];

                    int cnt;
                    cnt = Physics.OverlapSphereNonAlloc(point1, radius, _nonallocColliderBuffer, layerMask, query);
                    for (int i = 0; i < cnt; i++)
                    {
                        tmpSet.Add(_nonallocColliderBuffer[i]);
                        _nonallocColliderBuffer[i] = null;
                    }

                    cnt = Physics.OverlapSphereNonAlloc(point2, radius, _nonallocColliderBuffer, layerMask, query);
                    for (int i = 0; i < cnt; i++)
                    {
                        tmpSet.Add(_nonallocColliderBuffer[i]);
                        _nonallocColliderBuffer[i] = null;
                    }

                    var dir = point2 - point1;
                    var dist = dir.magnitude;
                    cnt = Physics.SphereCastNonAlloc(point1, radius, dir.normalized, _nonallocRaycastBuffer, dist, layerMask, query);
                    for (int i = 0; i < cnt; i++)
                    {
                        tmpSet.Add(_nonallocRaycastBuffer[i].collider);
                        _nonallocRaycastBuffer[i] = default(RaycastHit);
                    }
                }

                //done, now fill collection
                if (results is Collider[])
                {
                    var arr = results as Collider[];
                    int cnt = Mathf.Min(arr.Length, tmpSet.Count);
                    int i = -1;
                    var e = tmpSet.GetEnumerator();
                    while (e.MoveNext() && ++i < cnt)
                    {
                        arr[i] = e.Current;
                    }
                    return cnt;
                }
                else
                {
                    if (results is List<Collider>)
                    {
                        var lst = results as List<Collider>;
                        var num = tmpSet.Count + lst.Count;
                        if (lst.Capacity < num) lst.Capacity = num;
                    }

                    var e = tmpSet.GetEnumerator();
                    while (e.MoveNext())
                    {
                        results.Add(e.Current);
                    }
                    return tmpSet.Count;
                }
            }
        }
Пример #25
0
        private void DealWithDisable(MonoBehaviour component)
        {
            using (var lst = TempCollection.GetList <RadicalCoroutine>())
            {
                var e = _routines.GetEnumerator();
                while (e.MoveNext())
                {
                    if (e.Current.Owner == component)
                    {
                        lst.Add(e.Current);
                    }
                }

                if (lst.Count > 0)
                {
                    RadicalCoroutine routine;
                    if (ObjUtil.IsObjectAlive(this) && this.gameObject.activeInHierarchy)
                    {
                        for (int i = 0; i < lst.Count; i++)
                        {
                            routine = lst[i];
                            if ((routine.DisableMode & RadicalCoroutineDisableMode.CancelOnDisable) != 0)
                            {
                                routine.ManagerCancel();
                                _routines.Remove(routine);
                            }
                            else if ((routine.DisableMode & RadicalCoroutineDisableMode.StopOnDisable) != 0)
                            {
                                if (!routine.Finished && (routine.DisableMode & RadicalCoroutineDisableMode.Resumes) != 0)
                                {
                                    routine.Pause();
                                }
                                else
                                {
                                    routine.Stop();
                                    _routines.Remove(routine);
                                }
                            }
                        }
                    }
                    else
                    {
                        for (int i = 0; i < lst.Count; i++)
                        {
                            routine = lst[i];
                            if ((routine.DisableMode & RadicalCoroutineDisableMode.StopOnDeactivate) != 0)
                            {
                                if (!routine.Finished && (routine.DisableMode & RadicalCoroutineDisableMode.Resumes) != 0)
                                {
                                    routine.Pause();
                                }
                                else
                                {
                                    routine.Stop();
                                    _routines.Remove(routine);
                                }
                            }
                            else
                            {
                                routine.ManagerCancel();
                                _routines.Remove(routine);
                            }
                        }
                    }
                }
            }
        }