Esempio n. 1
0
        //------------------------------------------------------------------------/
        // Methods: Static
        //------------------------------------------------------------------------/
        /// <summary>
        /// Keeps watch of a given property/field
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="varExpr">An expression of a given variable of the form: '(()=> foo')</param>
        /// <param name="behaviour">The owner object of this variable</param>
        /// <example>Overlay.Watch(()=> foo, this);</example>
        public static void Watch <T>(Expression <Func <T> > varExpr, string description = null, MonoBehaviour behaviour = null)
        {
            StratusMemberReference variableRef = StratusReflection.GetReference(varExpr);
            Watcher watcher = new Watcher(variableRef, description, behaviour);

            instance.Windows.Watch.Add(watcher);
        }
Esempio n. 2
0
        /// <summary>
        /// Constructs and initializes all declared non-abstract derived displays.
        /// This will add them to the editor's SceneView GUI delegate
        /// </summary>
        private static void ConstructAllDisplays()
        {
            // Get a list of all display classes, then construct them
            Type[] displayClasses = StratusReflection.GetSubclass <SceneViewDisplay>();
            foreach (Type displayType in displayClasses)
            {
                SceneViewDisplay display = Activator.CreateInstance(displayType) as SceneViewDisplay;
                //SceneViewDisplay display = ScriptableObject.CreateInstance(displayType) as SceneViewDisplay;
                //display.name = displayType.Name;
                display.name = displayType.GetNiceName();
                displays.Add(display);
                displaysMap.Add(display.name, display);
            }

            // Now initialize them
            foreach (SceneViewDisplay display in displays)
            {
                display.loaded = display.Load();
                if (!display.loaded)
                {
                    display.OnReset();
                    display.Save();
                }

                display.InitializeDisplay();
            }
        }
Esempio n. 3
0
 public static void Open()
 {
     EditorWindow.GetWindow(typeof(BehaviorBrowserWindow), false, Title);
     Composites = StratusReflection.GenerateClassList <StratusAIComposite>();
     Actions    = StratusReflection.GenerateClassList <StratusAITask>();
     Decorators = StratusReflection.GenerateClassList <StratusAIService>();
 }
Esempio n. 4
0
        //------------------------------------------------------------------------/
        // Fields
        //------------------------------------------------------------------------/

        //------------------------------------------------------------------------/
        // CTOR
        //------------------------------------------------------------------------/
        public StratusTypeSelector(Type baseType, bool includeAbstract, bool sortAlphabetically = false)
        {
            this.baseType = baseType;
            this.subTypes = new StratusDropdownList <Type>(StratusReflection.GetSubclass(baseType), Name);
            if (sortAlphabetically)
            {
                this.subTypes.Sort();
            }
        }
Esempio n. 5
0
 static StratusSerializedEditorObject()
 {
     foreach (Type drawerType in customObjectDrawers)
     {
         ObjectDrawer drawer     = (ObjectDrawer)StratusReflection.Instantiate(drawerType);
         Type         objectType = drawer.type;
         objectDrawers.Add(objectType, drawer);
     }
 }
Esempio n. 6
0
        public StratusTypeSelector(Type baseType, Type interfaceType, bool sortAlphabetically = false)
        {
            this.baseType = baseType;
            this.subTypes = new StratusDropdownList <Type>(StratusReflection.GetInterfaces(baseType, interfaceType), (Type type) => type.Name);

            if (sortAlphabetically)
            {
                this.subTypes.Sort();
            }
        }
        //------------------------------------------------------------------------/
        // Data
        //------------------------------------------------------------------------/
        private List <EventTreeElement> BuildEventTree()
        {
            this.events = StratusReflection.GetSubclass <Stratus.StratusEvent>();
            EventInformation[] eventsInformation = new EventInformation[this.events.Length];
            for (int i = 0; i < this.events.Length; ++i)
            {
                eventsInformation[i] = new EventInformation(this.events[i]);
            }

            //var treeBuilder = new TreeBuilder<EventTreeElement, EventInformation>();
            //treeBuilder.AddChildren(eventsInformation, 0);
            //return treeBuilder.ToTree();

            tree = new StratusSerializedTree <EventTreeElement, EventInformation>(eventsInformation);
            return(tree.elements);
        }
Esempio n. 8
0
        private void GetMatchingExtensionTypes()
        {
            this.extensionAttributes = new List <Dictionary <Type, Attribute> >();

            List <Type> matchingTypes = new List <Type>();

            // 1. Get all extensible types who have marked support for this extensible
            var allExtensionTypes = StratusReflection.GetInterfaces(typeof(MonoBehaviour), extensionType);

            foreach (var type in allExtensionTypes)
            {
                var attributeMap = type.MapAttributes();
                this.extensionAttributes.Add(attributeMap);
                StratusCustomExtensionAttribute attribute = type.GetAttribute <StratusCustomExtensionAttribute>();
                if (attribute != null && attribute.supportedExtensibles.Contains(extensibleType))
                {
                    matchingTypes.Add(type);
                }
            }

            extensionTypes     = matchingTypes.ToArray();
            extensionTypeNames = matchingTypes.ToStringArray(x => x.Name);
        }
 public static int GetInspectorMode(this SerializedObject prop)
 {
     return(StratusReflection.GetProperty <int>("inspectorMode", typeof(SerializedObject), prop));
 }
 public static int GetHashCodeForPropertyPathWithoutArrayIndex(this SerializedProperty prop)
 {
     return(StratusReflection.GetProperty <int>("hashCodeForPropertyPathWithoutArrayIndex", typeof(SerializedProperty), prop));
 }
Esempio n. 11
0
        private static string DrawTypeSelectionControl(Rect position, GUIContent label, string classRef, ClassTypeConstraintAttribute filter)
        {
            if (label != null && label != GUIContent.none)
            {
                position = EditorGUI.PrefixLabel(position, label);
            }

            int controlID = GUIUtility.GetControlID(s_ControlHint, FocusType.Keyboard, position);

            bool triggerDropDown = false;

            switch (UnityEngine.Event.current.GetTypeForControl(controlID))
            {
            case EventType.ExecuteCommand:
                if (UnityEngine.Event.current.commandName == "TypeReferenceUpdated")
                {
                    if (s_SelectionControlID == controlID)
                    {
                        if (classRef != s_SelectedClassRef)
                        {
                            classRef    = s_SelectedClassRef;
                            GUI.changed = true;
                        }

                        s_SelectionControlID = 0;
                        s_SelectedClassRef   = null;
                    }
                }
                break;

            case EventType.MouseDown:
                if (GUI.enabled && position.Contains(UnityEngine.Event.current.mousePosition))
                {
                    GUIUtility.keyboardControl = controlID;
                    triggerDropDown            = true;
                    UnityEngine.Event.current.Use();
                }
                break;

            case EventType.KeyDown:
                if (GUI.enabled && GUIUtility.keyboardControl == controlID)
                {
                    if (UnityEngine.Event.current.keyCode == KeyCode.Return || UnityEngine.Event.current.keyCode == KeyCode.Space)
                    {
                        triggerDropDown = true;
                        UnityEngine.Event.current.Use();
                    }
                }
                break;

            case EventType.Repaint:
                // Remove assembly name from content of popup control.
                string[] classRefParts = classRef.Split(',');

                s_TempContent.text = classRefParts[0].Trim();
                if (s_TempContent.text == "")
                {
                    s_TempContent.text = "(None)";
                }
                else if (StratusReflection.ResolveType(classRef) == null)
                {
                    s_TempContent.text += " {Missing}";
                }

                EditorStyles.popup.Draw(position, s_TempContent, controlID);
                break;
            }

            if (triggerDropDown)
            {
                s_SelectionControlID = controlID;
                s_SelectedClassRef   = classRef;

                List <Type> filteredTypes = GetFilteredTypes(filter);
                DisplayDropDown(position, filteredTypes, StratusReflection.ResolveType(classRef), filter.Grouping);
            }

            return(classRef);
        }
Esempio n. 12
0
 public static StratusTypeSelector FilteredSelector(Type baseType, Type excludedType, bool includeAbstract, bool sortAlphabetically = true)
 {
     Type[] types = StratusReflection.GetSubclass(baseType).Where(x => !x.IsSubclassOf(excludedType)).ToArray();
     return(new StratusTypeSelector(types, includeAbstract, sortAlphabetically));
 }
Esempio n. 13
0
 public StratusTypeSelector(Type baseType, Predicate <Type> predicate, bool includeAbstract, bool sortAlphabetically = true)
     : this(StratusReflection.GetSubclass(baseType).Where(x => predicate(x)).ToArray(), includeAbstract, sortAlphabetically)
 {
 }
Esempio n. 14
0
 public static float GetPropertyHeightSafe(this PropertyDrawer drawer, SerializedProperty property, GUIContent label)
 {
     return((float)StratusReflection.GetReflectedMethod("GetPropertyHeightSafe", typeof(UnityEditor.PropertyDrawer), false, drawer).Invoke(drawer, new object[] { property, label }));
 }
Esempio n. 15
0
 public static void OnGUISafe(this PropertyDrawer drawer, Rect position, SerializedProperty property, GUIContent label)
 {
     StratusReflection.GetReflectedMethod("OnGUISafe", typeof(UnityEditor.PropertyDrawer), false, drawer).Invoke(drawer, new object[] { position, property, label });
 }
Esempio n. 16
0
 private static void ResetCache <T>(Type type) where T : StratusEvent, new() => eventCache[type] = (T)StratusReflection.Instantiate(type);
Esempio n. 17
0
 private static void Cache <T>(Type type) where T : StratusEvent, new() => eventCache.Add(type, (T)StratusReflection.Instantiate(type));
Esempio n. 18
0
 public static void SetFieldInfo(this PropertyDrawer drawer, FieldInfo info)
 {
     StratusReflection.SetField("m_FieldInfo", typeof(PropertyDrawer), info, false, drawer);
 }
Esempio n. 19
0
 public static void SetAttribute(this DecoratorDrawer drawer, PropertyAttribute attrib)
 {
     StratusReflection.SetField("m_Attribute", typeof(DecoratorDrawer), attrib, false, drawer);
 }
Esempio n. 20
0
 public static Type GetHiddenType(this CustomPropertyDrawer prop)
 {
     return(StratusReflection.GetField <Type>("m_Type", typeof(CustomPropertyDrawer), false, prop));
 }
Esempio n. 21
0
 public static bool GetUseForChildren(this CustomPropertyDrawer prop)
 {
     return(StratusReflection.GetField <bool>("m_UseForChildren", typeof(CustomPropertyDrawer), false, prop));
 }