public override void OnGUI (Rect position, SerializedProperty property, GUIContent label)
	{
		position.height = EditorGUIUtility.singleLineHeight;
		property = property.Copy();
		property.NextVisible(true);
		EditorGUI.PropertyField(position, property);
		position.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
		property.NextVisible(true);
		EditorGUI.PropertyField(position, property);
	}
        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            drawPrefixLabel = false;
            height = 0;

            Begin(position, property, label);

            position.height = EditorGUI.GetPropertyHeight(property, label, true);

            EditorGUI.PropertyField(position, property);

            if (property.GetValue() != null)
                property.isExpanded = EditorGUI.Foldout(position, property.isExpanded, GUIContent.none);

            height += position.height;
            position.y += position.height;

            if (property.isExpanded && serialized != null)
            {
                iterator = serialized.GetIterator();
                iterator.NextVisible(true);
                iterator.NextVisible(true);

                EditorGUI.indentLevel += 1;
                int currentIndent = EditorGUI.indentLevel;

                while (true)
                {
                    position.height = EditorGUI.GetPropertyHeight(iterator, iterator.displayName.ToGUIContent(), false);

                    height += position.height;

                    EditorGUI.indentLevel = currentIndent + iterator.depth;
                    EditorGUI.PropertyField(position, iterator);

                    position.y += position.height;

                    if (!iterator.NextVisible(iterator.isExpanded))
                    {
                        break;
                    }
                }

                EditorGUI.indentLevel = currentIndent;
                EditorGUI.indentLevel -= 1;

                serialized.ApplyModifiedProperties();
            }

            End();
        }
Exemplo n.º 3
0
        public static MonoBehaviourData MonoBehaviourDataFromSource(MonoBehaviour target, Hammurabi serializer)
        {
            MonoBehaviourData data = new MonoBehaviourData();

            data.n = "MonoBehaviour";
            SerializedObject serializableTarget = new SerializedObject(target);

            UnityEditor.SerializedProperty unityProperty  = serializableTarget.GetIterator();
            List <SerializedProperty>      propertiesList = new List <SerializedProperty>();

            while (unityProperty.NextVisible(true))
            {
                if (unityProperty.type == "int")
                {
                    SerializedProperty property = new SerializedProperty();
                    property.k = unityProperty.name;
                    property.t = SerializablePropertyType.Number;
                    property.v = unityProperty.intValue;
                    propertiesList.Add(property);
                }
                else if (unityProperty.type == "PPtr<MonoScript>")
                {
                    MonoScript script = unityProperty.objectReferenceValue as MonoScript;
                    serializer.LinkScript(script);
                    data.n = script.name;
                }
            }
            data.properties = propertiesList.ToArray();
            return(data);
        }
Exemplo n.º 4
0
		public static void CopyPropertyValue(SerializedProperty source, SerializedProperty dest)
		{
			source = source.Copy();
			dest = dest.Copy();

			var destSO = dest.serializedObject;


			if (source.hasVisibleChildren)
			{
				var sourceRoot = source.propertyPath;
				var destRoot = dest.propertyPath;

				while (source.NextVisible(true) && source.propertyPath.StartsWith(sourceRoot))
				{
					if (source.propertyType == SerializedPropertyType.Generic)
						continue;

					var path = destRoot + source.propertyPath.Remove(0, sourceRoot.Length);
					var destProperty = destSO.FindProperty(path);
					SetPropertyValue(destProperty, GetPropertyValue(source));
				}
			}
			else
			{
				if (dest.propertyPath == "m_RootOrder")
				{
					(dest.serializedObject.targetObject as Transform).SetSiblingIndex((int)GetPropertyValue(source));
				}
				SetPropertyValue(dest, GetPropertyValue(source));
			}
		}
        public void InitializeHeight(SerializedProperty property, GUIContent label)
        {
            height = EditorGUI.GetPropertyHeight(property, label, true);

            if (property.isExpanded && serialized != null)
            {
                iterator = serialized.GetIterator();
                iterator.NextVisible(true);
                iterator.NextVisible(true);

                while (true)
                {
                    height += EditorGUI.GetPropertyHeight(iterator, iterator.displayName.ToGUIContent(), false);

                    if (!iterator.NextVisible(iterator.isExpanded))
                    {
                        break;
                    }
                }
            }
        }
        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            drawPrefixLabel = false;
            totalHeight = 0;

            Begin(position, property, label);

            position.height = EditorGUI.GetPropertyHeight(property, label, true);
            EditorGUI.PropertyField(position, property);
            totalHeight += position.height;
            position.y += position.height;

            if (property.objectReferenceValue != null) {
                serialized = new SerializedObject(property.objectReferenceValue);
                iterator = serialized.GetIterator();
                iterator.NextVisible(true);

                EditorGUI.indentLevel += 1;
                int indent = EditorGUI.indentLevel;
                while (true) {
                    position.height = EditorGUI.GetPropertyHeight(iterator, iterator.displayName.ToGUIContent(), false);

                    totalHeight += position.height;
                    EditorGUI.indentLevel = indent + iterator.depth;
                    EditorGUI.PropertyField(position, iterator);
                    position.y += position.height;

                    if (!iterator.NextVisible(iterator.isExpanded)) {
                        break;
                    }
                }

                EditorGUI.indentLevel = indent;
                EditorGUI.indentLevel -= 1;

                serialized.ApplyModifiedProperties();
            }

            End();
        }
Exemplo n.º 7
0
    public static void ArrayField(SerializedProperty property)
    {
        //EditorGUIUtility.LookLikeInspector();
        bool wasEnabled = GUI.enabled;
        int prevIdentLevel = EditorGUI.indentLevel;

        bool childrenAreExpanded = true;
        int propertyStartingDepth = property.depth;
        while (property.NextVisible(childrenAreExpanded) && propertyStartingDepth < property.depth)
        {
            childrenAreExpanded = EditorGUILayout.PropertyField(property);
        }

        EditorGUI.indentLevel = prevIdentLevel;
        GUI.enabled = wasEnabled;
    }
Exemplo n.º 8
0
        internal bool OptimizedInspectorGUIImplementation(Rect contentRect)
        {
            SerializedProperty iterator = this.m_SerializedObject.GetIterator();
            bool enterChildren          = true;
            bool enabled = GUI.enabled;

            contentRect.xMin += 14f;
            contentRect.xMax -= 4f;
            contentRect.y    += 2f;
            while (iterator.NextVisible(enterChildren))
            {
                contentRect.height    = EditorGUI.GetPropertyHeight(iterator, (GUIContent)null, false);
                EditorGUI.indentLevel = iterator.depth;
                using (new EditorGUI.DisabledGroupScope(this.m_InspectorMode == InspectorMode.Normal && "m_Script" == iterator.propertyPath))
                    enterChildren = EditorGUI.PropertyField(contentRect, iterator);
                contentRect.y += contentRect.height + 2f;
            }
            GUI.enabled = enabled;
            return(this.m_SerializedObject.ApplyModifiedProperties());
        }
Exemplo n.º 9
0
        internal static bool DoDrawDefaultInspector(SerializedObject obj)
        {
            EditorGUI.BeginChangeCheck();
            obj.UpdateIfRequiredOrScript();

            // Loop through properties and create one field (including children) for each top level property.
            SerializedProperty property = obj.GetIterator();
            bool expanded = true;
            while (property.NextVisible(expanded))
            {
                using (new EditorGUI.DisabledScope("m_Script" == property.propertyPath))
                {
                    EditorGUILayout.PropertyField(property, true);
                }
                expanded = false;
            }

            obj.ApplyModifiedProperties();
            return EditorGUI.EndChangeCheck();
        }
Exemplo n.º 10
0
        internal bool GetOptimizedGUIBlockImplementation(bool isDirty, bool isVisible, out OptimizedGUIBlock block, out float height)
        {
            if (this.m_OptimizedBlock == null)
            {
                this.m_OptimizedBlock = new OptimizedGUIBlock();
            }
            block = this.m_OptimizedBlock;
            bool result;

            if (!isVisible)
            {
                height = 0f;
                result = true;
            }
            else
            {
                if (this.m_SerializedObject == null)
                {
                    this.m_SerializedObject = new SerializedObject(this.targets, this.m_Context);
                }
                else
                {
                    this.m_SerializedObject.Update();
                }
                this.m_SerializedObject.inspectorMode = this.m_InspectorMode;
                SerializedProperty iterator = this.m_SerializedObject.GetIterator();
                height = 2f;
                bool enterChildren = true;
                while (iterator.NextVisible(enterChildren))
                {
                    height       += EditorGUI.GetPropertyHeight(iterator, null, true) + 2f;
                    enterChildren = false;
                }
                if (height == 2f)
                {
                    height = 0f;
                }
                result = true;
            }
            return(result);
        }
Exemplo n.º 11
0
        internal bool CanBeExpandedViaAFoldoutWithoutUpdate()
        {
            if (m_SerializedObject == null)
            {
                CreateSerializedObject();
            }
            SerializedProperty property = m_SerializedObject.GetIterator();

            bool analyzePropertyChildren = true;

            while (property.NextVisible(analyzePropertyChildren))
            {
                if (EditorGUI.GetPropertyHeight(property, null, true) > 0)
                {
                    return(true);
                }
                analyzePropertyChildren = false;
            }

            return(false);
        }
Exemplo n.º 12
0
	void PropertyField (SerializedProperty sp, string name)
	{
		if (sp.hasChildren) {
            
            GUILayout.BeginVertical();
			while (true) {
				if (sp.propertyPath != name && !sp.propertyPath.StartsWith (name + "."))
					break;

				EditorGUI.indentLevel = sp.depth;
                bool child = false;

                child = sp.depth == 0 ? EditorGUILayout.PropertyField(sp, new GUIContent(dispName)) : EditorGUILayout.PropertyField(sp);

				if (!sp.NextVisible (child))
					break;
			}
            EditorGUI.indentLevel = 0;
            GUILayout.EndVertical();
		} else EditorGUILayout.PropertyField(sp, new GUIContent(dispName));
	}
Exemplo n.º 13
0
        public float GetHeight(SerializedProperty property, GUIContent label, bool includeChildren)
        {
            float height = 0;

            if (m_DecoratorDrawers != null && !isCurrentlyNested)
            {
                foreach (DecoratorDrawer drawer in m_DecoratorDrawers)
                {
                    height += drawer.GetHeight();
                }
            }

            if (propertyDrawer != null)
            {
                height += propertyDrawer.GetPropertyHeightSafe(property.Copy(), label ?? EditorGUIUtility.TempContent(property.displayName));
            }
            else if (!includeChildren)
            {
                height += EditorGUI.GetSinglePropertyHeight(property, label);
            }
            else
            {
                property = property.Copy();
                SerializedProperty endProperty = property.GetEndProperty();

                // First property with custom label
                height += EditorGUI.GetSinglePropertyHeight(property, label);
                bool childrenAreExpanded = property.isExpanded && EditorGUI.HasVisibleChildFields(property);

                // Loop through all child properties
                while (property.NextVisible(childrenAreExpanded) && !SerializedProperty.EqualContents(property, endProperty))
                {
                    height += ScriptAttributeUtility.GetHandler(property).GetHeight(property, EditorGUIUtility.TempContent(property.displayName), true);
                    childrenAreExpanded = false;
                    height += EditorGUI.kControlVerticalSpacing;
                }
            }

            return(height);
        }
Exemplo n.º 14
0
        public float GetHeight(SerializedProperty property, GUIContent label, bool includeChildren)
        {
            float num1 = 0.0f;

            if (this.m_DecoratorDrawers != null && !this.isCurrentlyNested)
            {
                using (List <DecoratorDrawer> .Enumerator enumerator = this.m_DecoratorDrawers.GetEnumerator())
                {
                    while (enumerator.MoveNext())
                    {
                        DecoratorDrawer current = enumerator.Current;
                        num1 += current.GetHeight();
                    }
                }
            }
            float num2;

            if (this.propertyDrawer != null)
            {
                num2 = num1 + this.propertyDrawer.GetPropertyHeightSafe(property.Copy(), label ?? EditorGUIUtility.TempContent(property.displayName));
            }
            else if (!includeChildren)
            {
                num2 = num1 + EditorGUI.GetSinglePropertyHeight(property, label);
            }
            else
            {
                property = property.Copy();
                SerializedProperty endProperty = property.GetEndProperty();
                num2 = num1 + EditorGUI.GetSinglePropertyHeight(property, label);
                bool enterChildren = property.isExpanded && EditorGUI.HasVisibleChildFields(property);
                while (property.NextVisible(enterChildren) && !SerializedProperty.EqualContents(property, endProperty))
                {
                    float num3 = num2 + ScriptAttributeUtility.GetHandler(property).GetHeight(property, EditorGUIUtility.TempContent(property.displayName), true);
                    enterChildren = false;
                    num2          = num3 + 2f;
                }
            }
            return(num2);
        }
Exemplo n.º 15
0
        internal bool CanBeExpandedViaAFoldout()
        {
            if (this.m_SerializedObject == null)
            {
                this.m_SerializedObject = new SerializedObject(this.targets);
            }
            else
            {
                this.m_SerializedObject.Update();
            }
            this.m_SerializedObject.inspectorMode = this.m_InspectorMode;
            SerializedProperty iterator = this.m_SerializedObject.GetIterator();

            for (bool flag = true; iterator.NextVisible(flag); flag = false)
            {
                if (EditorGUI.GetPropertyHeight(iterator, null, true) > 0f)
                {
                    return(true);
                }
            }
            return(false);
        }
Exemplo n.º 16
0
        internal bool CanBeExpandedViaAFoldout()
        {
            if (this.m_SerializedObject == null)
            {
                this.m_SerializedObject = new SerializedObject(this.targets);
            }
            else
            {
                this.m_SerializedObject.Update();
            }
            this.m_SerializedObject.inspectorMode = this.m_InspectorMode;
            SerializedProperty iterator = this.m_SerializedObject.GetIterator();

            for (bool enterChildren = true; iterator.NextVisible(enterChildren); enterChildren = false)
            {
                if ((double)EditorGUI.GetPropertyHeight(iterator, (GUIContent)null, true) > 0.0)
                {
                    return(true);
                }
            }
            return(false);
        }
        public bool CanCacheInspectorGUI(SerializedProperty property)
        {
            if (m_DecoratorDrawers != null &&
                !isCurrentlyNested &&
                m_DecoratorDrawers.Any(decorator => !decorator.CanCacheInspectorGUI()))
            {
                return(false);
            }

            if (propertyDrawer != null)
            {
                return(propertyDrawer.CanCacheInspectorGUISafe(property.Copy()));
            }

            property = property.Copy();

            bool childrenAreExpanded = property.isExpanded && EditorGUI.HasVisibleChildFields(property);

            // Loop through all child properties
            if (childrenAreExpanded)
            {
                PropertyHandler    handler     = null;
                SerializedProperty endProperty = property.GetEndProperty();
                while (property.NextVisible(childrenAreExpanded) && !SerializedProperty.EqualContents(property, endProperty))
                {
                    if (handler == null)
                    {
                        handler = ScriptAttributeUtility.GetHandler(property);
                    }
                    if (!handler.CanCacheInspectorGUI(property))
                    {
                        return(false);
                    }
                    childrenAreExpanded = false;
                }
            }

            return(true);
        }
Exemplo n.º 18
0
        public void GetSelectedStyleProperty(out SerializedObject serializedObject, out SerializedProperty styleProperty)
        {
            GUISkin  gUISkin  = null;
            GUISkin  current  = GUISkin.current;
            GUIStyle gUIStyle = current.FindStyle(this.m_Instruction.usedGUIStyle.name);

            if (gUIStyle != null && gUIStyle == this.m_Instruction.usedGUIStyle)
            {
                gUISkin = current;
            }
            styleProperty = null;
            if (gUISkin != null)
            {
                serializedObject = new SerializedObject(gUISkin);
                SerializedProperty iterator = serializedObject.GetIterator();
                bool enterChildren          = true;
                while (iterator.NextVisible(enterChildren))
                {
                    if (iterator.type == "GUIStyle")
                    {
                        enterChildren = false;
                        SerializedProperty serializedProperty = iterator.FindPropertyRelative("m_Name");
                        if (serializedProperty.stringValue == this.m_Instruction.usedGUIStyle.name)
                        {
                            styleProperty = iterator;
                            return;
                        }
                    }
                    else
                    {
                        enterChildren = true;
                    }
                }
                Debug.Log(string.Format("Showing editable Style from GUISkin: {0}, IsPersistant: {1}", gUISkin.name, EditorUtility.IsPersistent(gUISkin)));
            }
            serializedObject = new SerializedObject(this.m_CachedinstructionInfo.styleContainer);
            styleProperty    = serializedObject.FindProperty("inspectedStyle");
        }
        protected void ShowDerivedProperties(System.Type baseType, System.Type superType)
        {
            bool flag = true;
            SerializedProperty iterator = this.serializedObject.GetIterator();
            bool enterChildren          = true;

            while (iterator.NextVisible(enterChildren))
            {
                System.Reflection.FieldInfo field = baseType.GetField(iterator.name, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
                PropertyInfo property             = baseType.GetProperty(iterator.name, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
                if (field == null && superType != null)
                {
                    field = superType.GetField(iterator.name, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
                }
                if (property == null && superType != null)
                {
                    property = superType.GetProperty(iterator.name, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
                }
                if (field == null && property == null)
                {
                    if (flag)
                    {
                        flag = false;
                        EditorGUI.BeginChangeCheck();
                        this.serializedObject.Update();
                        EditorGUILayout.Separator();
                    }
                    EditorGUILayout.PropertyField(iterator, true, new GUILayoutOption[0]);
                    enterChildren = false;
                }
            }
            if (flag)
            {
                return;
            }
            this.serializedObject.ApplyModifiedProperties();
            EditorGUI.EndChangeCheck();
        }
Exemplo n.º 20
0
        public float GetHeight(SerializedProperty property, GUIContent label, bool includeChildren)
        {
            float num = 0f;

            if (this.m_DecoratorDrawers != null)
            {
                foreach (DecoratorDrawer current in this.m_DecoratorDrawers)
                {
                    num += current.GetHeight();
                }
            }
            if (this.propertyDrawer != null)
            {
                num += this.propertyDrawer.GetPropertyHeightSafe(property.Copy(), label ?? EditorGUIUtility.TempContent(property.displayName));
            }
            else
            {
                if (!includeChildren)
                {
                    num += EditorGUI.GetSinglePropertyHeight(property, label);
                }
                else
                {
                    property = property.Copy();
                    SerializedProperty endProperty = property.GetEndProperty();
                    num += EditorGUI.GetSinglePropertyHeight(property, label);
                    bool enterChildren = property.isExpanded && EditorGUI.HasVisibleChildFields(property);
                    while (property.NextVisible(enterChildren) && !SerializedProperty.EqualContents(property, endProperty))
                    {
                        num          += ScriptAttributeUtility.GetHandler(property).GetHeight(property, EditorGUIUtility.TempContent(property.displayName), true);
                        enterChildren = false;
                        num          += 2f;
                    }
                }
            }
            return(num);
        }
Exemplo n.º 21
0
	void ArrayGUI (SerializedProperty sp, string name)
	{
		EditorGUIUtility.LookLikeControls (100.0f, 40.0f);
		GUILayout.Space (4.0f);
		EditorGUILayout.BeginVertical ("box", GUILayout.MaxWidth(Screen.width));

		int i = 0;
		int del = -1;

		SerializedProperty array = sp.Copy ();
		SerializedProperty size = null;
		bool first = true;

		while (true) {
			if (sp.propertyPath != name && !sp.propertyPath.StartsWith (name + "."))
				break;

			bool child;
            EditorGUI.indentLevel = sp.depth;

			if (sp.depth == 1 && !first) {
				EditorGUILayout.BeginHorizontal ();

				if (GUILayout.Button ("", "OL Minus", GUILayout.Width (24.0f)))
					del = i;

				//GUILayout.Label ("" + i);
				child = EditorGUILayout.PropertyField (sp);

				GUI.enabled = i > 0;

				if (GUILayout.Button (manager.arrowUp, "ButtonLeft", GUILayout.Width (22.0f), GUILayout.Height(18.0f)))
					array.MoveArrayElement (i - 1, i);

				GUI.enabled = i < array.arraySize - 1;
                if (GUILayout.Button(manager.arrowDown, "ButtonRight", GUILayout.Width(22.0f), GUILayout.Height(18.0f)))
					array.MoveArrayElement (i + 1, i);

				++i;

				GUI.enabled = true;
				EditorGUILayout.EndHorizontal ();
			} else if (sp.depth == 1) {
				first = false;
				size = sp.Copy ();

				EditorGUILayout.BeginHorizontal ();

                if (!size.hasMultipleDifferentValues && GUILayout.Button("", "OL Plus", GUILayout.Width(24.0f)))
					array.arraySize += 1;


				child = EditorGUILayout.PropertyField (sp);

				EditorGUILayout.EndHorizontal ();
			} else {
                child = EditorGUILayout.PropertyField(sp);
			}

			if (!sp.NextVisible (child))
				break;
		}

		sp.Reset ();

		if (del != -1)
			array.DeleteArrayElementAtIndex (del);

		if (array.isExpanded && !size.hasMultipleDifferentValues) {
			EditorGUILayout.BeginHorizontal ();

            if (GUILayout.Button("", "OL Plus", GUILayout.Width(24.0f)))
				array.arraySize += 1;

			GUI.enabled = false;
			EditorGUILayout.PropertyField (array.GetArrayElementAtIndex (array.arraySize - 1), new GUIContent ("" + array.arraySize));
			GUI.enabled = true;

			EditorGUILayout.EndHorizontal ();
		}


        EditorGUI.indentLevel = 0;
		EditorGUILayout.EndVertical ();
		EditorGUIUtility.LookLikeControls (170.0f, 80.0f);
	}
Exemplo n.º 22
0
		internal static void MultiPropertyField(Rect position, GUIContent[] subLabels, SerializedProperty valuesIterator, float labelWidth, bool[] disabledMask)
		{
			int num = subLabels.Length;
			float num2 = (position.width - (float)(num - 1) * 2f) / (float)num;
			Rect position2 = new Rect(position);
			position2.width = num2;
			float labelWidth2 = EditorGUIUtility.labelWidth;
			int indentLevel = EditorGUI.indentLevel;
			EditorGUIUtility.labelWidth = labelWidth;
			EditorGUI.indentLevel = 0;
			for (int i = 0; i < subLabels.Length; i++)
			{
				if (disabledMask != null)
				{
					EditorGUI.BeginDisabledGroup(disabledMask[i]);
				}
				EditorGUI.PropertyField(position2, valuesIterator, subLabels[i]);
				if (disabledMask != null)
				{
					EditorGUI.EndDisabledGroup();
				}
				position2.x += num2 + 2f;
				valuesIterator.NextVisible(false);
			}
			EditorGUIUtility.labelWidth = labelWidth2;
			EditorGUI.indentLevel = indentLevel;
		}
        protected void IterateSerializedProp(SerializedProperty property)
        {
            if (property.NextVisible(true))
            {
                // Remember depth iteration started from
                int depth = property.Copy().depth;
                do
                {
                    // If goes deeper than the iteration depth, get out
                    if (property.depth != depth)
                        break;

                    DrawPropertySortableArray(property);
                } while (property.NextVisible(false));
            }
        }
Exemplo n.º 24
0
		void DrawFunctionBlockUI(){
						
			Color c = Handles.color;
			Handles.color = Color.yellow;
			
			float radius = functionBlock.blockMap.tileScale.y * 0.4f;
			
			Handles.DrawWireDisc(functionBlock.transform.position,functionBlock.transform.forward,radius);
			
			Handles.color = c;
			
			Vector2 pos = HandleUtility.WorldToGUIPoint(functionBlock.transform.position);
			
			Handles.BeginGUI();
			
			Rect r = new Rect(pos.x - 150.0f,pos.y + 25.0f,300.0f,175.0f);
			
			//GUI.skin = TidyEditorUtility.GetEditorGUISkin();
			
			//GUI.Box(r,"");
			
			//GUI.skin = null;
			
			GUI.DrawTexture(r,GetIcon(TidyFileNames.AREA_BACKGROUND));
			
			GUILayout.BeginArea(r);
			
			GUILayout.BeginVertical();
			
			GUILayout.Space(10.0f);
			
			if(functionData == null){
				//draw the 'add data' UI
				
				
			
				//draw the close UI
				GUILayout.BeginHorizontal();
				
				GUILayout.Label("Add object:");
				
				GUILayout.FlexibleSpace();
				
				if(GUILayout.Button("X")){
					SetEntireMapDirty(functionBlock.blockMap);
					functionBlock = null;
					functionData = null;
					prop = null;
				}
				
				GUILayout.EndHorizontal();
				
				if(functionalComponents != null && functionalComponents.Length > 0){
					for(int i = 0; i < functionalComponents.Length; i++){
						
						if(GUILayout.Button(functionalComponents[i].name)){
						
							TidyFunctionalObject o = UnityEngineInternal.APIUpdaterRuntimeServices.AddComponent(functionBlock.blockMap.gameObject, "Assets/Tidy Tile Mapper/Editor/Editor Logic/TidyMapCreator.cs (1502,33)", functionalComponents[i].name) as TidyFunctionalObject;
							
							o.SetParentBlock(functionBlock);
														
							functionBlock.blockMap.functionalOverlay.AddData(o);
							
							SetEntireMapDirty(functionBlock.blockMap);
							
							SetFunctionBlock(functionBlock);
														
						}
						
					}
				}
				else{
					GUILayout.Label("None");
				}
				
				
			}
			else{
				
				GUILayout.Label(functionData.parentBlock.name + " at " +"["+functionData.parentBlock.x + "," + functionData.parentBlock.y + "," + functionData.parentBlock.depth+"]");
				
				//draw the close UI
				GUILayout.BeginHorizontal();
				
				GUILayout.Label(functionData.GetType().Name);
				
				GUILayout.FlexibleSpace();
				
				if(GUILayout.Button("X")){
					SetEntireMapDirty(functionBlock.blockMap);
					functionBlock = null;
					functionData = null;
					prop= null;
				}
				
				GUILayout.EndHorizontal();
				
				GUILayout.Space(10.0f);
				
				fScrollPos = GUILayout.BeginScrollView(fScrollPos);
								
				try{
							
					prop = functionSObj.GetIterator();
					
					if(prop != null && functionSObj != null && functionData != null){
												
						prop.NextVisible(true);
											
						bool searchDeep = true;
						
						do{
														
							searchDeep = true;
							
							if(prop.propertyPath == "m_Script"){
								continue;
							}
							
							if(prop.name == "parentBlock"){
								continue;
							}
							
							if(prop.type == "Vector3f"){
								searchDeep = false;
							}
							
							if(prop.type == "Vector3f" && prop.name == "targetDifference" && currentTidyTarget != null){
								
								prop.vector3Value = currentTidyTarget.targetDifference;
								
								currentTidyTarget = null;
							}
							
							if(prop.name == "TidyTarget_parentBlock" && currentTidyTarget != null){
								
								prop.objectReferenceValue = currentTidyTarget.TidyTarget_parentBlock;
								
							}
							
							if(prop.type == "TidyTarget"){
																	
								EditorGUILayout.BeginHorizontal();
							
								GUILayout.Label(prop.name + ":");
								
								GUILayout.FlexibleSpace();
								
								Color gc = GUI.color;
								
								if(setTidyTarget == true){
									GUI.color = Color.green;
								}
								
								if(GUILayout.Button("Set")){
									setTidyTarget = true;
									//tidyTargetName = prop.name;
									currentTidyTarget = null;
								}
								
								GUI.color = gc;
								
								EditorGUILayout.EndHorizontal();
								
								continue;
							}
						
							EditorGUILayout.BeginHorizontal();
							EditorGUILayout.PropertyField(prop);
							
							EditorGUILayout.EndHorizontal();
							
						}while(prop.NextVisible(searchDeep));
						
						prop.Reset();
						
						functionSObj.ApplyModifiedProperties();	
						
						functionSObj.Update();
					}
					else{
						GUILayout.Label("Data null.");
					}
					
				}catch(Exception e){Debug.LogWarning(e.ToString());}
					
				GUILayout.EndScrollView();
				
				GUILayout.BeginHorizontal();
				
				GUILayout.FlexibleSpace();
				
				if(GUILayout.Button("Delete")){
					
					TidyFunctionalObject o = functionBlock.blockMap.functionalOverlay.RemoveDataAt(functionBlock.x,functionBlock.y,functionBlock.depth);
					
					GameObject.DestroyImmediate(o);
					
					functionData = null;
					prop = null;
										
					SetEntireMapDirty(functionBlock.blockMap);
					
					functionBlock = null;
				}
				
				GUILayout.EndHorizontal();
			}
						
			GUILayout.EndVertical();
				
			GUILayout.EndArea();
			
			Handles.EndGUI();
		}
Exemplo n.º 25
0
	//Copy One Module's Values
	private void GenericModuleCopy(SerializedProperty ss, SerializedProperty sd, bool depthBreak = true)
	{
		while(true)
		{
			//Next Property
			if(!ss.NextVisible(true))
			{
				break;
			}
			sd.NextVisible(true);
			
			//If end of module: break
			if(depthBreak && ss.depth == 0)
			{
				break;
			}
			
			bool found = true;
			
			switch(ss.propertyType)
			{
				case SerializedPropertyType.Boolean : 			sd.boolValue = ss.boolValue; break;
				case SerializedPropertyType.Integer : 			sd.intValue = ss.intValue; break;
				case SerializedPropertyType.Float : 			sd.floatValue = ss.floatValue; break;
				case SerializedPropertyType.Color : 			sd.colorValue = ss.colorValue; break;
				case SerializedPropertyType.Bounds : 			sd.boundsValue = ss.boundsValue; break;
				case SerializedPropertyType.Enum : 				sd.enumValueIndex = ss.enumValueIndex; break;
				case SerializedPropertyType.ObjectReference : 	sd.objectReferenceValue = ss.objectReferenceValue; break;
				case SerializedPropertyType.Rect : 				sd.rectValue = ss.rectValue; break;
				case SerializedPropertyType.String : 			sd.stringValue = ss.stringValue; break;
				case SerializedPropertyType.Vector2 : 			sd.vector2Value = ss.vector2Value; break;
				case SerializedPropertyType.Vector3 : 			sd.vector3Value = ss.vector3Value; break;
				case SerializedPropertyType.AnimationCurve : 	sd.animationCurveValue = ss.animationCurveValue; break;
#if !UNITY_3_5
				case SerializedPropertyType.Gradient :			copyGradient(ss,sd); break;
#endif
				
				default: found = false; break;
			}
			
			if(!found)
			{
				found = true;
				
				switch(ss.type)
				{
					default: found = false; break;
				}
			}
		}
		
		//Apply Changes
		sd.serializedObject.ApplyModifiedProperties();
		
		ss.Dispose();
		sd.Dispose();
	}
Exemplo n.º 26
0
		public float GetHeight(SerializedProperty property, GUIContent label, bool includeChildren)
		{
			float num = 0f;
			if (this.m_DecoratorDrawers != null)
			{
				foreach (DecoratorDrawer current in this.m_DecoratorDrawers)
				{
					num += current.GetHeight();
				}
			}
			if (this.propertyDrawer != null)
			{
				num += this.propertyDrawer.GetPropertyHeightSafe(property.Copy(), label ?? EditorGUIUtility.TempContent(property.displayName));
			}
			else
			{
				if (!includeChildren)
				{
					num += EditorGUI.GetSinglePropertyHeight(property, label);
				}
				else
				{
					property = property.Copy();
					SerializedProperty endProperty = property.GetEndProperty();
					num += EditorGUI.GetSinglePropertyHeight(property, label);
					bool enterChildren = property.isExpanded && EditorGUI.HasVisibleChildFields(property);
					while (property.NextVisible(enterChildren) && !SerializedProperty.EqualContents(property, endProperty))
					{
						num += ScriptAttributeUtility.GetHandler(property).GetHeight(property, EditorGUIUtility.TempContent(property.displayName), true);
						enterChildren = false;
						num += 2f;
					}
				}
			}
			return num;
		}
Exemplo n.º 27
0
        public override object DrawControl(Rect position, SerializedProperty property, GUIContent label, object value)
        {
            var attr = (GroupAttribute)attribute;

            if (fieldInfo.FieldType.IsClass &&
                !typeof(Object).IsAssignableFrom(fieldInfo.FieldType) &&
                !typeof(IList).IsAssignableFrom(fieldInfo.FieldType)) {

                if (attr.drawFoldout) {
                    EditorGUI.PropertyField(position, property, label, true);
                } else {
                    property.isExpanded = true;

                    SerializedProperty endProperty = property.GetEndProperty();
                    property.NextVisible(true);

                    while (!SerializedProperty.EqualContents(property, endProperty)) {
                        position.height = EditorGUI.GetPropertyHeight(property);
                        EditorGUI.PropertyField(position, property, true);
                        position.y += position.height + EditorGUIUtility.standardVerticalSpacing;
                        property.NextVisible(false);
                    }
                }

                return value;
            } else {
                throw new InvalidCastException(String.Format(
                    "Field '{0}' of type '{1}' must be a class not derived from UnityEngine.Object to be used with the Inspector.Group attribute.",
                    fieldInfo.Name, fieldInfo.FieldType));
            }
        }
Exemplo n.º 28
0
	private bool PropsInArrayMismatched(SerializedProperty props) {
		string original = props.propertyPath;

		props.Next(true);
		props.Next(true);
		props.Next(true);

		//some weird unity behaviour where it collapses the array 
		if (!props.propertyPath.Contains(original)) {
			return true;
		}

		do {
			var nameProp = props.FindPropertyRelative("first.name");

			if (nameProp.hasMultipleDifferentValues) {
				return true;
			}
		} while (props.NextVisible(false) && props.propertyPath.Contains(original));



		return false;
	}
Exemplo n.º 29
0
        internal override bool GetOptimizedGUIBlock(bool isDirty, bool isVisible, out float height)
        {
            height = -1;

            // Don't use optimizedGUI for audio filters
            var behaviour = target as MonoBehaviour;

            if (behaviour != null && AudioUtil.HasAudioCallback(behaviour) && AudioUtil.GetCustomFilterChannelCount(behaviour) > 0)
            {
                return(false);
            }

            if (ObjectIsMonoBehaviourOrScriptableObject(target))
            {
                return(false);
            }

            if (isDirty)
            {
                ResetOptimizedBlock();
            }

            if (!isVisible)
            {
                height = 0;
                return(true);
            }

            // Return cached result if any.
            if (m_OptimizedBlockState != OptimizedBlockState.CheckOptimizedBlock)
            {
                if (m_OptimizedBlockState == OptimizedBlockState.NoOptimizedBlock)
                {
                    return(false);
                }
                height = m_LastHeight;
                return(true);
            }

            // Update serialized object representation
            if (m_SerializedObject == null)
            {
                m_SerializedObject = new SerializedObject(targets, m_Context)
                {
                    inspectorMode = inspectorMode
                }
            }
            ;
            else
            {
                m_SerializedObject.Update();
                m_SerializedObject.inspectorMode = inspectorMode;
            }

            height = 0;
            SerializedProperty property = m_SerializedObject.GetIterator();
            bool childrenAreExpanded    = true;

            while (property.NextVisible(childrenAreExpanded))
            {
                var handler = ScriptAttributeUtility.GetHandler(property);
                height += handler.GetHeight(property, null, false) + EditorGUI.kControlVerticalSpacing;

                childrenAreExpanded = property.isExpanded && EditorGUI.HasVisibleChildFields(property);
            }

            m_LastHeight          = height;
            m_OptimizedBlockState = OptimizedBlockState.HasOptimizedBlock;

            return(true);
        }
        internal bool GetOptimizedGUIBlockImplementation(bool isDirty, bool isVisible, out OptimizedGUIBlock block, out float height)
        {
            if (isDirty && m_OptimizedBlock != null)
            {
                m_OptimizedBlock.Dispose();
                m_OptimizedBlock = null;
            }

            if (!isVisible)
            {
                if (m_OptimizedBlock == null)
                {
                    m_OptimizedBlock = new OptimizedGUIBlock();
                }
                block  = m_OptimizedBlock;
                height = 0;
                return(true);
            }

            if (m_SerializedObject == null)
            {
                m_SerializedObject = new SerializedObject(targets, m_Context);
            }
            else
            {
                m_SerializedObject.Update();
            }
            m_SerializedObject.inspectorMode = m_InspectorMode;

            SerializedProperty property = m_SerializedObject.GetIterator();

            height = EditorGUI.kControlVerticalSpacing;
            bool expand = true;

            while (property.NextVisible(expand))
            {
                if (!EditorGUI.CanCacheInspectorGUI(property))
                {
                    if (m_OptimizedBlock != null)
                    {
                        m_OptimizedBlock.Dispose();
                    }
                    block = m_OptimizedBlock = null;
                    return(false);
                }

                height += EditorGUI.GetPropertyHeight(property, null, true) + EditorGUI.kControlVerticalSpacing;
                expand  = false;
            }

            if (height == EditorGUI.kControlVerticalSpacing)
            {
                height = 0;
            }

            if (m_OptimizedBlock == null)
            {
                m_OptimizedBlock = new OptimizedGUIBlock();
            }
            block = m_OptimizedBlock;
            return(true);
        }
    /// <summary>
    /// Draws the size of the array.
    /// </summary>
    void DrawArraySize( ref Rect position, SerializedProperty property, Object targetObject, string targetPropertyPath, bool openMenu, Vector3 mousePos )
    {
        property = property.Copy();
        property.NextVisible( true );
        EditorGUI.PropertyField( position, property );

        // Right-Click-Menu.
        if( openMenu && position.Contains( mousePos ) )
        { OpenArraySizeFieldMenu( targetObject, targetPropertyPath, mousePos ); }

        position.y += EditorGUI.GetPropertyHeight( property );
    }
Exemplo n.º 32
0
	private void AddPropsFromArray(PropType type, SerializedProperty props) {
		string original = props.propertyPath;

		props.Next(true);
		props.Next(true);
		props.Next(true);

		do {
			var valueProp = props.FindPropertyRelative("second");
			var nameProp = props.FindPropertyRelative("first.name");



			string propName = nameProp.stringValue;

			AddProperty(propName, type, valueProp);
		} while (props.NextVisible(false) && props.propertyPath.Contains(original));
	}
Exemplo n.º 33
0
        internal bool OnGUI(Rect position, SerializedProperty property, GUIContent label, bool includeChildren, Rect visibleArea)
        {
            TestInvalidateCache();

            float oldLabelWidth, oldFieldWidth;

            float propHeight = position.height;

            position.height = 0;
            if (m_DecoratorDrawers != null && !isCurrentlyNested)
            {
                foreach (DecoratorDrawer decorator in m_DecoratorDrawers)
                {
                    position.height = decorator.GetHeight();

                    oldLabelWidth = EditorGUIUtility.labelWidth;
                    oldFieldWidth = EditorGUIUtility.fieldWidth;
                    decorator.OnGUI(position);
                    EditorGUIUtility.labelWidth = oldLabelWidth;
                    EditorGUIUtility.fieldWidth = oldFieldWidth;

                    position.y += position.height;
                    propHeight -= position.height;
                }
            }

            position.height = propHeight;
            if (propertyDrawer != null)
            {
                // Remember widths
                oldLabelWidth = EditorGUIUtility.labelWidth;
                oldFieldWidth = EditorGUIUtility.fieldWidth;
                // Draw with custom drawer - retrieve it BEFORE increasing nesting.
                PropertyDrawer drawer = propertyDrawer;

                using (var nestingContext = IncrementNestingContext())
                {
                    drawer.OnGUISafe(position, property.Copy(), label ?? EditorGUIUtility.TempContent(property.localizedDisplayName, tooltip));
                }

                // Restore widths
                EditorGUIUtility.labelWidth = oldLabelWidth;
                EditorGUIUtility.fieldWidth = oldFieldWidth;

                return(false);
            }
            else
            {
                if (!includeChildren)
                {
                    return(EditorGUI.DefaultPropertyField(position, property, label));
                }

                if (UseReorderabelListControl(property))
                {
                    ReorderableListWrapper reorderableList;
                    string key = ReorderableListWrapper.GetPropertyIdentifier(property);

                    if (!s_reorderableLists.TryGetValue(key, out reorderableList))
                    {
                        // Manual layout controls don't call GetHeight() method so we need to have a way to initialized list as we prepare to render it here
                        reorderableList         = new ReorderableListWrapper(property, label, true);
                        s_reorderableLists[key] = reorderableList;
                    }

                    // Calculate visibility rect specifically for reorderable list as when applied for the whole serialized object,
                    // it causes collapsed out of sight array elements appear thus messing up scroll-bar experience
                    var screenPos = GUIUtility.GUIToScreenPoint(position.position);

                    screenPos.y = Mathf.Clamp(screenPos.y,
                                              GUIView.current?.screenPosition.yMin ?? 0,
                                              GUIView.current?.screenPosition.yMax ?? Screen.height);

                    Rect listVisibility = new Rect(screenPos.x, screenPos.y,
                                                   GUIView.current?.screenPosition.width ?? Screen.width,
                                                   GUIView.current?.screenPosition.height ?? Screen.height);

                    listVisibility = GUIUtility.ScreenToGUIRect(listVisibility);

                    reorderableList.Property = property;
                    reorderableList.Draw(label, position, listVisibility, tooltip, includeChildren);
                    return(!includeChildren && property.isExpanded);
                }

                // Remember state
                Vector2 oldIconSize = EditorGUIUtility.GetIconSize();
                bool    wasEnabled  = GUI.enabled;
                int     origIndent  = EditorGUI.indentLevel;

                int relIndent = origIndent - property.depth;

                SerializedProperty prop = property.Copy();

                position.height = EditorGUI.GetSinglePropertyHeight(prop, label);

                // First property with custom label
                EditorGUI.indentLevel = prop.depth + relIndent;
                bool childrenAreExpanded = EditorGUI.DefaultPropertyField(position, prop, label) && EditorGUI.HasVisibleChildFields(prop);
                position.y += position.height + EditorGUI.kControlVerticalSpacing;

                // Loop through all child properties
                if (childrenAreExpanded)
                {
                    SerializedProperty endProperty = prop.GetEndProperty();
                    while (prop.NextVisible(childrenAreExpanded) && !SerializedProperty.EqualContents(prop, endProperty))
                    {
                        var handler = ScriptAttributeUtility.GetHandler(prop);
                        EditorGUI.indentLevel = prop.depth + relIndent;
                        position.height       = handler.GetHeight(prop, null, UseReorderabelListControl(prop) && includeChildren);

                        if (position.Overlaps(visibleArea))
                        {
                            EditorGUI.BeginChangeCheck();
                            childrenAreExpanded = handler.OnGUI(position, prop, null, UseReorderabelListControl(prop)) && EditorGUI.HasVisibleChildFields(prop);
                            // Changing child properties (like array size) may invalidate the iterator,
                            // so stop now, or we may get errors.
                            if (EditorGUI.EndChangeCheck())
                            {
                                break;
                            }
                        }

                        position.y += position.height + EditorGUI.kControlVerticalSpacing;
                    }
                }

                // Restore state
                GUI.enabled = wasEnabled;
                EditorGUIUtility.SetIconSize(oldIconSize);
                EditorGUI.indentLevel = origIndent;

                return(false);
            }
        }
Exemplo n.º 34
0
        public float GetHeight(SerializedProperty property, GUIContent label, bool includeChildren)
        {
            float height = 0;

            if (m_DecoratorDrawers != null && !isCurrentlyNested)
            {
                foreach (DecoratorDrawer drawer in m_DecoratorDrawers)
                {
                    height += drawer.GetHeight();
                }
            }


            if (propertyDrawer != null)
            {
                // Retrieve drawer BEFORE increasing nesting.
                PropertyDrawer drawer = propertyDrawer;
                using (var nestingContext = IncrementNestingContext())
                {
                    height += drawer.GetPropertyHeightSafe(property.Copy(), label ?? EditorGUIUtility.TempContent(property.localizedDisplayName, tooltip));
                }
            }
            else if (!includeChildren)
            {
                height += EditorGUI.GetSinglePropertyHeight(property, label);
            }
            else if (UseReorderabelListControl(property))
            {
                ReorderableListWrapper reorderableList;
                string key = ReorderableListWrapper.GetPropertyIdentifier(property);

                // If collection doesn't have a ReorderableList assigned to it, create one and assign it
                if (!s_reorderableLists.TryGetValue(key, out reorderableList))
                {
                    reorderableList         = new ReorderableListWrapper(property, label, true);
                    s_reorderableLists[key] = reorderableList;
                }

                reorderableList.Property = property;
                height += s_reorderableLists[key].GetHeight();
                return(height);
            }
            else
            {
                property = property.Copy();

                // First property with custom label
                height += EditorGUI.GetSinglePropertyHeight(property, label);
                bool childrenAreExpanded = property.isExpanded && EditorGUI.HasVisibleChildFields(property);

                // Loop through all child properties
                var tc = EditorGUIUtility.TempContent(property.localizedDisplayName, tooltip);
                if (childrenAreExpanded)
                {
                    SerializedProperty endProperty = property.GetEndProperty();
                    while (property.NextVisible(childrenAreExpanded) && !SerializedProperty.EqualContents(property, endProperty))
                    {
                        height += ScriptAttributeUtility.GetHandler(property).GetHeight(property, tc, true);
                        childrenAreExpanded = false;
                        height += EditorGUI.kControlVerticalSpacing;
                    }
                }
            }

            return(height);
        }
 public override void OnInspectorGUI()
 {
     if (!this.m_FormatSupported.HasValue)
     {
         this.m_FormatSupported = true;
         foreach (UnityEngine.Object obj2 in base.targets)
         {
             TrueTypeFontImporter importer = obj2 as TrueTypeFontImporter;
             if ((importer == null) || !importer.IsFormatSupported())
             {
                 this.m_FormatSupported = false;
             }
         }
     }
     if (this.m_FormatSupported == false)
     {
         this.ShowFormatUnsupportedGUI();
     }
     else
     {
         EditorGUILayout.PropertyField(this.m_FontSize, new GUILayoutOption[0]);
         if (this.m_FontSize.intValue < 1)
         {
             this.m_FontSize.intValue = 1;
         }
         if (this.m_FontSize.intValue > 500)
         {
             this.m_FontSize.intValue = 500;
         }
         EditorGUILayout.IntPopup(this.m_FontRenderingMode, kRenderingModeStrings, kRenderingModeValues, new GUIContent("Rendering Mode"), new GUILayoutOption[0]);
         EditorGUILayout.IntPopup(this.m_TextureCase, kCharacterStrings, kCharacterValues, new GUIContent("Character"), new GUILayoutOption[0]);
         if (!this.m_TextureCase.hasMultipleDifferentValues)
         {
             if (this.m_TextureCase.intValue != -2)
             {
                 if (this.m_TextureCase.intValue == 3)
                 {
                     EditorGUI.BeginChangeCheck();
                     GUILayout.BeginHorizontal(new GUILayoutOption[0]);
                     EditorGUILayout.PrefixLabel("Custom Chars");
                     EditorGUI.showMixedValue = this.m_CustomCharacters.hasMultipleDifferentValues;
                     GUILayoutOption[] options = new GUILayoutOption[] { GUILayout.MinHeight(32f) };
                     string            source  = EditorGUILayout.TextArea(this.m_CustomCharacters.stringValue, GUI.skin.textArea, options);
                     EditorGUI.showMixedValue = false;
                     GUILayout.EndHorizontal();
                     if (EditorGUI.EndChangeCheck())
                     {
                         source = new string(source.Distinct <char>().ToArray <char>());
                         source = source.Replace("\n", string.Empty).Replace("\r", string.Empty);
                         this.m_CustomCharacters.stringValue = source;
                     }
                 }
             }
             else
             {
                 EditorGUILayout.PropertyField(this.m_IncludeFontData, new GUIContent("Incl. Font Data"), new GUILayoutOption[0]);
                 if (base.targets.Length == 1)
                 {
                     EditorGUI.BeginChangeCheck();
                     GUILayout.BeginHorizontal(new GUILayoutOption[0]);
                     EditorGUILayout.PrefixLabel("Font Names");
                     GUI.SetNextControlName("fontnames");
                     GUILayoutOption[] optionArray2 = new GUILayoutOption[] { GUILayout.MinHeight(32f) };
                     this.m_FontNamesString = EditorGUILayout.TextArea(this.m_FontNamesString, "TextArea", optionArray2);
                     GUILayout.EndHorizontal();
                     GUILayout.BeginHorizontal(new GUILayoutOption[0]);
                     GUILayout.FlexibleSpace();
                     EditorGUI.BeginDisabledGroup(this.m_FontNamesString == this.m_DefaultFontNamesString);
                     if (GUILayout.Button("Reset", "MiniButton", new GUILayoutOption[0]))
                     {
                         GUI.changed = true;
                         if (GUI.GetNameOfFocusedControl() == "fontnames")
                         {
                             GUIUtility.keyboardControl = 0;
                         }
                         this.m_FontNamesString = this.m_DefaultFontNamesString;
                     }
                     EditorGUI.EndDisabledGroup();
                     GUILayout.EndHorizontal();
                     if (EditorGUI.EndChangeCheck())
                     {
                         this.SetFontNames(this.m_FontNamesString);
                     }
                     this.m_ReferencesExpanded = EditorGUILayout.Foldout(this.m_ReferencesExpanded, "References to other fonts in project");
                     if (this.m_ReferencesExpanded)
                     {
                         EditorGUILayout.HelpBox("These are automatically generated by the inspector if any of the font names you supplied match fonts present in your project, which will then be used as fallbacks for this font.", MessageType.Info);
                         if (this.m_FallbackFontReferencesArraySize.intValue > 0)
                         {
                             SerializedProperty property = this.m_FallbackFontReferencesArraySize.Copy();
                             while (property.NextVisible(true) && (property.depth == 1))
                             {
                                 EditorGUILayout.PropertyField(property, true, new GUILayoutOption[0]);
                             }
                         }
                         else
                         {
                             EditorGUI.BeginDisabledGroup(true);
                             GUILayout.Label("No references to other fonts in project.", new GUILayoutOption[0]);
                             EditorGUI.EndDisabledGroup();
                         }
                     }
                 }
             }
         }
         base.ApplyRevertGUI();
     }
 }
        internal override bool GetOptimizedGUIBlock(bool isDirty, bool isVisible, out OptimizedGUIBlock block, out float height)
        {
            block = null; height = -1;

            // Don't use optimizedGUI for audio filters
            var behaviour = target as MonoBehaviour;

            if (behaviour != null && AudioUtil.HasAudioCallback(behaviour) && AudioUtil.GetCustomFilterChannelCount(behaviour) > 0)
            {
                return(false);
            }

            if (IsMissingMonoBehaviourTarget())
            {
                return(false);
            }

            if (isDirty && m_OptimizedBlock != null)
            {
                ResetOptimizedBlock();
            }

            if (!isVisible)
            {
                if (m_OptimizedBlock == null)
                {
                    m_OptimizedBlock = new OptimizedGUIBlock();
                }

                height = 0;
                block  = m_OptimizedBlock;
                return(true);
            }

            // Return cached result if any.
            if (m_OptimizedBlockState != OptimizedBlockState.CheckOptimizedBlock)
            {
                if (m_OptimizedBlockState == OptimizedBlockState.NoOptimizedBlock)
                {
                    return(false);
                }
                height = m_LastHeight;
                block  = m_LastOptimizedBlock;
                return(true);
            }

            // Update serialized object representation
            if (m_SerializedObject == null)
            {
                m_SerializedObject = new SerializedObject(targets, m_Context)
                {
                    inspectorMode = m_InspectorMode
                }
            }
            ;
            else
            {
                m_SerializedObject.Update();
                m_SerializedObject.inspectorMode = m_InspectorMode;
            }

            height = 0;
            SerializedProperty property = m_SerializedObject.GetIterator();

            while (property.NextVisible(height <= 0))
            {
                var handler = ScriptAttributeUtility.GetHandler(property);
                if (!handler.CanCacheInspectorGUI(property))
                {
                    return(ResetOptimizedBlock(OptimizedBlockState.NoOptimizedBlock));
                }

                // Allocate height for control plus spacing below it
                height += handler.GetHeight(property, null, true) + EditorGUI.kControlVerticalSpacing;
            }

            // Allocate height for spacing above first control
            if (height > 0)
            {
                height += EditorGUI.kControlVerticalSpacing;
            }

            if (m_OptimizedBlock == null)
            {
                m_OptimizedBlock = new OptimizedGUIBlock();
            }

            m_LastHeight          = height;
            m_LastOptimizedBlock  = block = m_OptimizedBlock;
            m_OptimizedBlockState = OptimizedBlockState.HasOptimizedBlock;
            return(true);
        }
Exemplo n.º 37
0
        public bool OnGUI(Rect position, SerializedProperty property, GUIContent label, bool includeChildren)
        {
            float num = position.height;

            position.height = 0f;
            if (this.m_DecoratorDrawers != null && !this.isCurrentlyNested)
            {
                foreach (DecoratorDrawer current in this.m_DecoratorDrawers)
                {
                    position.height = current.GetHeight();
                    float labelWidth = EditorGUIUtility.labelWidth;
                    float fieldWidth = EditorGUIUtility.fieldWidth;
                    current.OnGUI(position);
                    EditorGUIUtility.labelWidth = labelWidth;
                    EditorGUIUtility.fieldWidth = fieldWidth;
                    position.y += position.height;
                    num        -= position.height;
                }
            }
            position.height = num;
            if (this.propertyDrawer != null)
            {
                float labelWidth = EditorGUIUtility.labelWidth;
                float fieldWidth = EditorGUIUtility.fieldWidth;
                this.propertyDrawer.OnGUISafe(position, property.Copy(), label ?? EditorGUIUtility.TempContent(property.displayName));
                EditorGUIUtility.labelWidth = labelWidth;
                EditorGUIUtility.fieldWidth = fieldWidth;
                return(false);
            }
            if (!includeChildren)
            {
                return(EditorGUI.DefaultPropertyField(position, property, label));
            }
            Vector2            iconSize           = EditorGUIUtility.GetIconSize();
            bool               enabled            = GUI.enabled;
            int                indentLevel        = EditorGUI.indentLevel;
            int                num2               = indentLevel - property.depth;
            SerializedProperty serializedProperty = property.Copy();
            SerializedProperty endProperty        = serializedProperty.GetEndProperty();

            position.height       = EditorGUI.GetSinglePropertyHeight(serializedProperty, label);
            EditorGUI.indentLevel = serializedProperty.depth + num2;
            bool enterChildren = EditorGUI.DefaultPropertyField(position, serializedProperty, label) && EditorGUI.HasVisibleChildFields(serializedProperty);

            position.y += position.height + 2f;
            while (serializedProperty.NextVisible(enterChildren) && !SerializedProperty.EqualContents(serializedProperty, endProperty))
            {
                EditorGUI.indentLevel = serializedProperty.depth + num2;
                position.height       = EditorGUI.GetPropertyHeight(serializedProperty, null, false);
                EditorGUI.BeginChangeCheck();
                enterChildren = (ScriptAttributeUtility.GetHandler(serializedProperty).OnGUI(position, serializedProperty, null, false) && EditorGUI.HasVisibleChildFields(serializedProperty));
                if (EditorGUI.EndChangeCheck())
                {
                    break;
                }
                position.y += position.height + 2f;
            }
            GUI.enabled = enabled;
            EditorGUIUtility.SetIconSize(iconSize);
            EditorGUI.indentLevel = indentLevel;
            return(false);
        }
Exemplo n.º 38
0
 public static float GetPropertyHeight(SerializedProperty property, GUIContent label)
 {
     //PropertyDrawer drawer = PropertyDrawer.GetDrawer(property);
     //if (drawer != null)
     //{
     //    return drawer.GetPropertyHeight(property.Copy(), label ?? EditorGUIUtility.TempContent(property.displayName));
     //}
     property = property.Copy();
     SerializedProperty endProperty = property.GetEndProperty();
     float height = EditorGUIEx.GetSinglePropertyHeight(property, label);
     bool enterChildren = property.isExpanded && EditorGUIEx.HasVisibleChildFields(property);
     while (property.NextVisible(enterChildren) && !SerializedProperty.EqualContents(property, endProperty))
     {
         //drawer = PropertyDrawer.GetDrawer(property);
         //if (drawer != null)
         //{
         //    height += drawer.GetPropertyHeight(property.Copy(), EditorGUIUtility.TempContent(property.displayName));
         //    enterChildren = false;
         //}
         //else
         {
             height += EditorGUIEx.GetSinglePropertyHeight(property);
             enterChildren = (property.isExpanded && EditorGUIEx.HasVisibleChildFields(property));
         }
     }
     return height;
 }
        public override void OnInspectorGUI()
        {
            if (!this.m_Initialized)
            {
                this.serializedObject.Update();
                SerializedProperty property = this.serializedObject.FindProperty("m_Script");
                if (property == null)
                {
                    return;
                }
                this.Init(property.objectReferenceValue as MonoScript);
            }
            EditorGUI.BeginChangeCheck();
            this.serializedObject.Update();
            SerializedProperty iterator = this.serializedObject.GetIterator();

            for (bool enterChildren = true; iterator.NextVisible(enterChildren); enterChildren = false)
            {
                bool flag = this.m_SyncVarNames.Contains(iterator.name);
                if (iterator.propertyType == SerializedPropertyType.ObjectReference)
                {
                    EditorGUILayout.PropertyField(iterator, true, new GUILayoutOption[0]);
                }
                else
                {
                    EditorGUILayout.BeginHorizontal();
                    EditorGUILayout.PropertyField(iterator, true, new GUILayoutOption[0]);
                    if (flag)
                    {
                        GUILayout.Label("SyncVar", EditorStyles.toolbarTextField, new GUILayoutOption[1]
                        {
                            GUILayout.Width(52f)
                        });
                    }
                    EditorGUILayout.EndHorizontal();
                }
            }
            this.serializedObject.ApplyModifiedProperties();
            EditorGUI.EndChangeCheck();
            int index = 0;

            foreach (System.Reflection.FieldInfo field in this.serializedObject.targetObject.GetType().GetFields())
            {
                if (field.FieldType.BaseType != null && field.FieldType.BaseType.Name.Contains("SyncList"))
                {
                    this.m_ShowSyncLists[index] = (EditorGUILayout.Foldout((this.m_ShowSyncLists[index] ? 1 : 0) != 0, "SyncList " + field.Name + "  [" + field.FieldType.Name + "]") ? 1 : 0) != 0;
                    if (this.m_ShowSyncLists[index])
                    {
                        ++EditorGUI.indentLevel;
                        IEnumerable enumerable = field.GetValue((object)this.serializedObject.targetObject) as IEnumerable;
                        if (enumerable != null)
                        {
                            int         num        = 0;
                            IEnumerator enumerator = enumerable.GetEnumerator();
                            while (enumerator.MoveNext())
                            {
                                if (enumerator.Current != null)
                                {
                                    EditorGUILayout.LabelField("Item:" + (object)num, enumerator.Current.ToString(), new GUILayoutOption[0]);
                                }
                                ++num;
                            }
                        }
                        --EditorGUI.indentLevel;
                    }
                    ++index;
                }
            }
            if (!this.m_HasOnSerialize)
            {
                return;
            }
            NetworkBehaviour target = this.target as NetworkBehaviour;

            if (!((UnityEngine.Object)target != (UnityEngine.Object)null))
            {
                return;
            }
            EditorGUILayout.LabelField(this.m_NetworkChannelLabel, new GUIContent(target.GetNetworkChannel().ToString()), new GUILayoutOption[0]);
            EditorGUILayout.LabelField(this.m_NetworkSendIntervalLabel, new GUIContent(target.GetNetworkSendInterval().ToString()), new GUILayoutOption[0]);
        }
    void DrawConfig( SerializedProperty sp , int num)
    {
        sp.NextVisible( true );

        _foldoutStates[ num ].allOut = EditorGUILayout.Foldout( _foldoutStates[ num ].allOut, sp.stringValue );

        if( !_foldoutStates[ num ].allOut ) return;

        EditorGUI.indentLevel +=1 ;

        bool isAxis, isBirDir;

        {
             _foldoutStates[ num ].parameters = EditorGUILayout.Foldout( _foldoutStates[ num ].parameters, "Parameters" );
            EditorGUI.indentLevel ++;
            {
                //NAME
                if(_foldoutStates[ num ].parameters)sp.stringValue = EditorGUILayout.TextField( sp.name, sp.stringValue );

                //DESCRIPTION
                sp.NextVisible( false );
                if(_foldoutStates[ num ].parameters) sp.stringValue = EditorGUILayout.TextField( "Description", sp.stringValue );

                //TAB
                sp.NextVisible( false );
                if(_foldoutStates[ num ].parameters) sp.stringValue = EditorGUILayout.TextField( "Tab" , sp.stringValue );

                //PLAYER NUMBER
                sp.NextVisible( false );
                if(_foldoutStates[ num ].parameters) sp.intValue = EditorGUILayout.IntField( "Player", sp.intValue );

                if(_foldoutStates[ num ].parameters) EditorGUILayout.Space();

                //IS AXIS
                sp.NextVisible( false );
                if(_foldoutStates[ num ].parameters) sp.boolValue = EditorGUILayout.Toggle( "Is An Axis", sp.boolValue );
                isAxis = sp.boolValue;

                EditorGUI.indentLevel +=1;
                {
                    //GRAVITY
                    sp.NextVisible( false );
                    if(isAxis && _foldoutStates[ num ].parameters) sp.floatValue = EditorGUILayout.FloatField( sp.name, sp.floatValue );

                    //SENSITIVITY
                    sp.NextVisible( false );
                    if(isAxis && _foldoutStates[ num ].parameters) sp.floatValue = EditorGUILayout.FloatField( sp.name, sp.floatValue );
                }
                EditorGUI.indentLevel -=1 ;

                //IS BIDIRECTIONAL
                if( isAxis )
                {
                    if(_foldoutStates[ num ].parameters) EditorGUILayout.Space();

                    sp.NextVisible( false );
                    if(_foldoutStates[ num ].parameters) sp.boolValue = EditorGUILayout.Toggle( "Is A Bidirectional Axis", sp.boolValue );
                    isBirDir = sp.boolValue;

                    EditorGUI.indentLevel +=1;
                    {
                        //GRAVITY
                        sp.NextVisible( false );
                        if(isBirDir && _foldoutStates[ num ].parameters) sp.stringValue = EditorGUILayout.TextField( sp.name, sp.stringValue );

                        //SENSITIVITY
                        sp.NextVisible( false );
                        if(isBirDir && _foldoutStates[ num ].parameters) sp.enumValueIndex = EditorGUILayout.Popup( "Direction", sp.enumValueIndex, sp.enumNames);
                    }
                    EditorGUI.indentLevel -=1;
                }
                else
                {
                        sp.NextVisible( false );
                        sp.NextVisible( false );
                        sp.NextVisible( false );
                }
                //if(_foldoutStates[ num ].parameters) EditorGUILayout.Space();
            }
            EditorGUI.indentLevel --;

            //KEYBOARD INPUT
            _foldoutStates[ num ].keyboardOut = EditorGUILayout.Foldout(_foldoutStates[ num ].keyboardOut, "Keyboard Input");
            EditorGUI.indentLevel +=1;
            if(_foldoutStates[ num ].keyboardOut){
                //KEYBOARD POS
                sp.NextVisible( false );
                sp.stringValue = EditorGUILayout.TextField("Key", sp.stringValue );

                //KEYBOARD NEG
                sp.NextVisible( false );
                if(isAxis) sp.stringValue = EditorGUILayout.TextField("Negative Key", sp.stringValue );
            }
            else
            {
                sp.NextVisible( false );
                sp.NextVisible( false );
            }
            EditorGUI.indentLevel -=1;

            //EditorGUILayout.Space();

            //MOUSE INPUT
            _foldoutStates[ num ].mouseOut = EditorGUILayout.Foldout(_foldoutStates[ num ].mouseOut, "Mouse Input");
            EditorGUI.indentLevel +=1;
            if(_foldoutStates[ num ].mouseOut ){
                //MOUSE POS
                sp.NextVisible( false );
                sp.stringValue = EditorGUILayout.TextField("Mouse Button", sp.stringValue );

                //MOUSE NEG
                sp.NextVisible( false );
                if(isAxis) sp.stringValue = EditorGUILayout.TextField("Negative Mouse Button", sp.stringValue );

                //MOUSE AXIS
                sp.NextVisible( false );
                if(isAxis) sp.enumValueIndex = EditorGUILayout.Popup("Mouse Axis", sp.enumValueIndex, sp.enumNames );
            }
            else
            {
                sp.NextVisible( false );
                sp.NextVisible( false );
                sp.NextVisible( false );
            }
            EditorGUI.indentLevel -=1;

            //EditorGUILayout.Space();

            //JOYSTICK INPUT
            _foldoutStates[ num ].joyOut = EditorGUILayout.Foldout(_foldoutStates[ num ].joyOut, "Joystick Input");
            EditorGUI.indentLevel +=1;
            if(_foldoutStates[ num ].joyOut ){
                //JOYSTICK POS
                sp.NextVisible( false );
                sp.stringValue = EditorGUILayout.TextField("Joystick Button", sp.stringValue );

                //JOYSTICK NEG
                sp.NextVisible( false );
                if(isAxis) sp.stringValue = EditorGUILayout.TextField("Negative Joystick Button", sp.stringValue );

                //JOYSTICK AXIS
                sp.NextVisible( false );
                if(isAxis) sp.enumValueIndex = EditorGUILayout.Popup("Joystick Axis", sp.enumValueIndex, sp.enumNames );
            }
            else
            {
                sp.NextVisible( false );
                sp.NextVisible( false );
                sp.NextVisible( false );
            }
            EditorGUI.indentLevel -=1;

        }
        EditorGUI.indentLevel -=1;
    }
Exemplo n.º 41
0
        // returns true if children needs to be drawn separately
        public bool OnGUI(Rect position, SerializedProperty property, GUIContent label, bool includeChildren)
        {
            // We can consider making controlIDs robust to support culling optimizations.
            // Works well - downside is that you can't use PrefixLabel before a PropertyField,
            // but PropertyField has build-in label argument anyway.
            //if (m_Hash == 0)
            //  m_Hash = property.serializedObject.targetObject.GetInstanceID () ^ property.propertyPath.GetHashCode ();
            //EditorGUIUtility.GetControlID (m_Hash, FocusType.Passive);

            float oldLabelWidth, oldFieldWidth;

            float propHeight = position.height;

            position.height = 0;
            if (m_DecoratorDrawers != null && !isCurrentlyNested)
            {
                foreach (DecoratorDrawer decorator in m_DecoratorDrawers)
                {
                    position.height = decorator.GetHeight();

                    oldLabelWidth = EditorGUIUtility.labelWidth;
                    oldFieldWidth = EditorGUIUtility.fieldWidth;
                    decorator.OnGUI(position);
                    EditorGUIUtility.labelWidth = oldLabelWidth;
                    EditorGUIUtility.fieldWidth = oldFieldWidth;

                    position.y += position.height;
                    propHeight -= position.height;
                }
            }

            position.height = propHeight;
            if (propertyDrawer != null)
            {
                // Remember widths
                oldLabelWidth = EditorGUIUtility.labelWidth;
                oldFieldWidth = EditorGUIUtility.fieldWidth;
                // Draw with custom drawer
                propertyDrawer.OnGUISafe(position, property.Copy(), label ?? EditorGUIUtility.TempContent(property.localizedDisplayName));
                // Restore widths
                EditorGUIUtility.labelWidth = oldLabelWidth;
                EditorGUIUtility.fieldWidth = oldFieldWidth;

                return(false);
            }
            else
            {
                if (!includeChildren)
                {
                    return(EditorGUI.DefaultPropertyField(position, property, label));
                }

                // Remember state
                Vector2 oldIconSize = EditorGUIUtility.GetIconSize();
                bool    wasEnabled  = GUI.enabled;
                int     origIndent  = EditorGUI.indentLevel;

                int relIndent = origIndent - property.depth;

                SerializedProperty prop        = property.Copy();
                SerializedProperty endProperty = prop.GetEndProperty();

                position.height = EditorGUI.GetSinglePropertyHeight(prop, label);

                // First property with custom label
                EditorGUI.indentLevel = prop.depth + relIndent;
                bool childrenAreExpanded = EditorGUI.DefaultPropertyField(position, prop, label) && EditorGUI.HasVisibleChildFields(prop);
                position.y += position.height + EditorGUI.kControlVerticalSpacing;

                // Loop through all child properties
                while (prop.NextVisible(childrenAreExpanded) && !SerializedProperty.EqualContents(prop, endProperty))
                {
                    EditorGUI.indentLevel = prop.depth + relIndent;
                    position.height       = EditorGUI.GetPropertyHeight(prop, null, false);
                    EditorGUI.BeginChangeCheck();
                    childrenAreExpanded = ScriptAttributeUtility.GetHandler(prop).OnGUI(position, prop, null, false) && EditorGUI.HasVisibleChildFields(prop);
                    // Changing child properties (like array size) may invalidate the iterator,
                    // so stop now, or we may get errors.
                    if (EditorGUI.EndChangeCheck())
                    {
                        break;
                    }

                    position.y += position.height + EditorGUI.kControlVerticalSpacing;
                }

                // Restore state
                GUI.enabled = wasEnabled;
                EditorGUIUtility.SetIconSize(oldIconSize);
                EditorGUI.indentLevel = origIndent;

                return(false);
            }
        }
Exemplo n.º 42
0
    public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
    {
        EditorGUI.BeginProperty(position, label, property);

        SerializedProperty sourcePrefab = property.FindPropertyRelative("sourcePrefab");
        Rect propRect = position;
        propRect.height = propHeight;

#if UNITY_4_5
        string displayName = "No Source Prefab";
#else
            string displayName = property.displayName;
#endif

        if (Application.isPlaying)
        {
            EditorGUI.LabelField(propRect, string.Concat(sourcePrefab.objectReferenceValue != null ? sourcePrefab.objectReferenceValue.name : displayName, " Pool"), EditorStyles.objectFieldThumb);

            propRect.height = 18;
            propRect.y += propHeight + 1;

            SerializedProperty spCached = property.FindPropertyRelative("cached_internal");
            SerializedProperty spCapacity = property.FindPropertyRelative("Capacity");
            
            EditorGUI.ProgressBar(propRect, (float)spCached.intValue / spCapacity.intValue, string.Concat(spCached.intValue.ToString(), "/", spCapacity.intValue > 0 ? spCapacity.intValue.ToString() : "Unlimited"));
        }
        else
        {
            int indent = EditorGUI.indentLevel;
            EditorGUI.indentLevel = 1;

            //Draw custom foldout
            if (GUI.Button(propRect, sourcePrefab.objectReferenceValue != null ? sourcePrefab.objectReferenceValue.name : displayName, EditorStyles.objectFieldThumb))
                property.isExpanded = !property.isExpanded;
            if (property.isExpanded)
            {
                //Draw background
                Rect bgRect = new Rect(position.x, position.y + propHeight, position.width, position.height - propHeight);
                EditorGUI.HelpBox(bgRect, "", MessageType.None);

                //Draw sourcePrefab
                property = sourcePrefab;
                propRect.width -= 4;
                propRect.y += 4 + propHeight;
                EditorGUI.PropertyField(propRect, property);

                //Draw Capacity
                property.NextVisible(false);
                propRect.y += propHeight + 1;
                if (property.intValue < 0)
                    property.intValue = 0;
                EditorGUI.PropertyField(propRect, property);

                //Draw Preload
                int rightValue = property.intValue;
                property.NextVisible(false);
                propRect.y += propHeight + 1;
                if (rightValue > 0)
                {
                    if (property.intValue > rightValue)
                        property.intValue = rightValue;
                    EditorGUI.IntSlider(propRect, property, 0, rightValue);
                }
                else
                    EditorGUI.PropertyField(propRect, property);

                //Draw Notification Type and UseSceneClone
                for (int i = 0; i < 3; i++)
                {
                    property.NextVisible(false);
                    propRect.y += propHeight + 1;
                    EditorGUI.PropertyField(propRect, property);
                }
            }

            EditorGUI.indentLevel = indent;
        }

        EditorGUI.EndProperty();
    }
Exemplo n.º 43
0
 public float GetHeight(SerializedProperty property, GUIContent label, bool includeChildren)
 {
   float num1 = 0.0f;
   if (this.m_DecoratorDrawers != null && !this.isCurrentlyNested)
   {
     using (List<DecoratorDrawer>.Enumerator enumerator = this.m_DecoratorDrawers.GetEnumerator())
     {
       while (enumerator.MoveNext())
       {
         DecoratorDrawer current = enumerator.Current;
         num1 += current.GetHeight();
       }
     }
   }
   float num2;
   if (this.propertyDrawer != null)
     num2 = num1 + this.propertyDrawer.GetPropertyHeightSafe(property.Copy(), label ?? EditorGUIUtility.TempContent(property.displayName));
   else if (!includeChildren)
   {
     num2 = num1 + EditorGUI.GetSinglePropertyHeight(property, label);
   }
   else
   {
     property = property.Copy();
     SerializedProperty endProperty = property.GetEndProperty();
     num2 = num1 + EditorGUI.GetSinglePropertyHeight(property, label);
     bool enterChildren = property.isExpanded && EditorGUI.HasVisibleChildFields(property);
     while (property.NextVisible(enterChildren) && !SerializedProperty.EqualContents(property, endProperty))
     {
       float num3 = num2 + ScriptAttributeUtility.GetHandler(property).GetHeight(property, EditorGUIUtility.TempContent(property.displayName), true);
       enterChildren = false;
       num2 = num3 + 2f;
     }
   }
   return num2;
 }
        internal bool OnGUI(Rect position, SerializedProperty property, GUIContent label, bool includeChildren, Rect visibleArea)
        {
            float oldLabelWidth, oldFieldWidth;

            float propHeight = position.height;

            position.height = 0;
            if (m_DecoratorDrawers != null && !isCurrentlyNested)
            {
                foreach (DecoratorDrawer decorator in m_DecoratorDrawers)
                {
                    position.height = decorator.GetHeight();

                    oldLabelWidth = EditorGUIUtility.labelWidth;
                    oldFieldWidth = EditorGUIUtility.fieldWidth;
                    decorator.OnGUI(position);
                    EditorGUIUtility.labelWidth = oldLabelWidth;
                    EditorGUIUtility.fieldWidth = oldFieldWidth;

                    position.y += position.height;
                    propHeight -= position.height;
                }
            }

            position.height = propHeight;
            if (propertyDrawer != null)
            {
                // Remember widths
                oldLabelWidth = EditorGUIUtility.labelWidth;
                oldFieldWidth = EditorGUIUtility.fieldWidth;
                // Draw with custom drawer
                propertyDrawer.OnGUISafe(position, property.Copy(), label ?? EditorGUIUtility.TempContent(property.localizedDisplayName));
                // Restore widths
                EditorGUIUtility.labelWidth = oldLabelWidth;
                EditorGUIUtility.fieldWidth = oldFieldWidth;

                return(false);
            }
            else
            {
                if (!includeChildren)
                {
                    return(EditorGUI.DefaultPropertyField(position, property, label));
                }

                // Remember state
                Vector2 oldIconSize = EditorGUIUtility.GetIconSize();
                bool    wasEnabled  = GUI.enabled;
                int     origIndent  = EditorGUI.indentLevel;

                int relIndent = origIndent - property.depth;

                SerializedProperty prop = property.Copy();

                position.height = EditorGUI.GetSinglePropertyHeight(prop, label);

                // First property with custom label
                EditorGUI.indentLevel = prop.depth + relIndent;
                bool childrenAreExpanded = EditorGUI.DefaultPropertyField(position, prop, label) && EditorGUI.HasVisibleChildFields(prop);
                position.y += position.height + EditorGUI.kControlVerticalSpacing;

                // Loop through all child properties
                if (childrenAreExpanded)
                {
                    SerializedProperty endProperty = prop.GetEndProperty();
                    while (prop.NextVisible(childrenAreExpanded) && !SerializedProperty.EqualContents(prop, endProperty))
                    {
                        var handler = ScriptAttributeUtility.GetHandler(prop);
                        EditorGUI.indentLevel = prop.depth + relIndent;
                        position.height       = handler.GetHeight(prop, null, false);

                        if (position.Overlaps(visibleArea))
                        {
                            EditorGUI.BeginChangeCheck();
                            childrenAreExpanded = handler.OnGUI(position, prop, null, false) && EditorGUI.HasVisibleChildFields(prop);
                            // Changing child properties (like array size) may invalidate the iterator,
                            // so stop now, or we may get errors.
                            if (EditorGUI.EndChangeCheck())
                            {
                                break;
                            }
                        }

                        position.y += position.height + EditorGUI.kControlVerticalSpacing;
                    }
                }

                // Restore state
                GUI.enabled = wasEnabled;
                EditorGUIUtility.SetIconSize(oldIconSize);
                EditorGUI.indentLevel = origIndent;

                return(false);
            }
        }
Exemplo n.º 45
0
        public override void OnInspectorGUI()
        {
            if (!this.m_Initialized)
            {
                base.serializedObject.Update();
                SerializedProperty property = base.serializedObject.FindProperty("m_Script");
                if (property == null)
                {
                    return;
                }
                MonoScript objectReferenceValue = property.objectReferenceValue as MonoScript;
                this.Init(objectReferenceValue);
            }
            EditorGUI.BeginChangeCheck();
            base.serializedObject.Update();
            SerializedProperty iterator = base.serializedObject.GetIterator();

            for (bool flag = true; iterator.NextVisible(flag); flag = false)
            {
                bool flag2 = this.m_SyncVarNames.Contains(iterator.name);
                if (iterator.propertyType == SerializedPropertyType.ObjectReference)
                {
                    EditorGUILayout.PropertyField(iterator, true, new GUILayoutOption[0]);
                }
                else
                {
                    EditorGUILayout.BeginHorizontal(new GUILayoutOption[0]);
                    EditorGUILayout.PropertyField(iterator, true, new GUILayoutOption[0]);
                    if (flag2)
                    {
                        GUILayoutOption[] options = new GUILayoutOption[] { GUILayout.Width(52f) };
                        GUILayout.Label("SyncVar", EditorStyles.miniLabel, options);
                    }
                    EditorGUILayout.EndHorizontal();
                }
            }
            base.serializedObject.ApplyModifiedProperties();
            EditorGUI.EndChangeCheck();
            int index = 0;

            foreach (System.Reflection.FieldInfo info in base.serializedObject.targetObject.GetType().GetFields())
            {
                if ((info.FieldType.BaseType != null) && info.FieldType.BaseType.Name.Contains("SyncList"))
                {
                    this.m_ShowSyncLists[index] = EditorGUILayout.Foldout(this.m_ShowSyncLists[index], "SyncList " + info.Name + "  [" + info.FieldType.Name + "]");
                    if (this.m_ShowSyncLists[index])
                    {
                        EditorGUI.indentLevel++;
                        IEnumerable enumerable = info.GetValue(base.serializedObject.targetObject) as IEnumerable;
                        if (enumerable != null)
                        {
                            int         num3       = 0;
                            IEnumerator enumerator = enumerable.GetEnumerator();
                            while (enumerator.MoveNext())
                            {
                                if (enumerator.Current != null)
                                {
                                    EditorGUILayout.LabelField("Item:" + num3, enumerator.Current.ToString(), new GUILayoutOption[0]);
                                }
                                num3++;
                            }
                        }
                        EditorGUI.indentLevel--;
                    }
                    index++;
                }
            }
            if (this.m_HasOnSerialize)
            {
                NetworkBehaviour target = base.target as NetworkBehaviour;
                if (target != null)
                {
                    EditorGUILayout.LabelField(this.m_NetworkChannelLabel, new GUIContent(target.GetNetworkChannel().ToString()), new GUILayoutOption[0]);
                    EditorGUILayout.LabelField(this.m_NetworkSendIntervalLabel, new GUIContent(target.GetNetworkSendInterval().ToString()), new GUILayoutOption[0]);
                }
            }
        }
Exemplo n.º 46
0
        public override void OnInspectorGUI()
        {
            if (!m_Initialized)
            {
                serializedObject.Update();
                SerializedProperty scriptProperty = serializedObject.FindProperty("m_Script");
                if (scriptProperty == null)
                {
                    return;
                }

                MonoScript targetScript = scriptProperty.objectReferenceValue as MonoScript;
                Init(targetScript);
            }

            EditorGUI.BeginChangeCheck();
            serializedObject.Update();

            // Loop through properties and create one field (including children) for each top level property.
            SerializedProperty property = serializedObject.GetIterator();
            bool expanded = true;

            while (property.NextVisible(expanded))
            {
                bool isSyncVar = m_SyncVarNames.Contains(property.name);
                if (property.propertyType == SerializedPropertyType.ObjectReference)
                {
                    if (property.name == "m_Script")
                    {
                        if (hideScriptField)
                        {
                            continue;
                        }

                        EditorGUI.BeginDisabledGroup(true);
                    }

                    EditorGUILayout.PropertyField(property, true);

                    if (isSyncVar)
                    {
                        GUILayout.Label(m_SyncVarIndicatorContent, EditorStyles.miniLabel, GUILayout.Width(EditorStyles.miniLabel.CalcSize(m_SyncVarIndicatorContent).x));
                    }

                    if (property.name == "m_Script")
                    {
                        EditorGUI.EndDisabledGroup();
                    }
                }
                else
                {
                    EditorGUILayout.BeginHorizontal();

                    EditorGUILayout.PropertyField(property, true);

                    if (isSyncVar)
                    {
                        GUILayout.Label(m_SyncVarIndicatorContent, EditorStyles.miniLabel, GUILayout.Width(EditorStyles.miniLabel.CalcSize(m_SyncVarIndicatorContent).x));
                    }

                    EditorGUILayout.EndHorizontal();
                }
                expanded = false;
            }
            serializedObject.ApplyModifiedProperties();
            EditorGUI.EndChangeCheck();

            // find SyncLists.. they are not properties.
            int syncListIndex = 0;

            foreach (var field in serializedObject.targetObject.GetType().GetFields())
            {
                if (field.FieldType.BaseType != null && field.FieldType.BaseType.Name.Contains("SyncList"))
                {
                    m_ShowSyncLists[syncListIndex] = EditorGUILayout.Foldout(m_ShowSyncLists[syncListIndex], "SyncList " + field.Name + "  [" + field.FieldType.Name + "]");
                    if (m_ShowSyncLists[syncListIndex])
                    {
                        EditorGUI.indentLevel += 1;
                        var synclist = field.GetValue(serializedObject.targetObject) as IEnumerable;
                        if (synclist != null)
                        {
                            int index = 0;
                            var enu   = synclist.GetEnumerator();
                            while (enu.MoveNext())
                            {
                                if (enu.Current != null)
                                {
                                    EditorGUILayout.LabelField("Item:" + index, enu.Current.ToString());
                                }
                                index += 1;
                            }
                        }
                        EditorGUI.indentLevel -= 1;
                    }
                    syncListIndex += 1;
                }
            }

            if (m_HasOnSerialize)
            {
                var beh = target as NetworkBehaviour;
                if (beh != null)
                {
                    EditorGUILayout.LabelField(m_NetworkChannelLabel, new GUIContent(beh.GetNetworkChannel().ToString()));
                    EditorGUILayout.LabelField(m_NetworkSendIntervalLabel, new GUIContent(beh.GetNetworkSendInterval().ToString()));
                }
            }
        }
Exemplo n.º 47
0
 internal static void MultiPropertyField(Rect position, GUIContent[] subLabels, SerializedProperty valuesIterator, float labelWidth, bool[] disabledMask)
 {
   int length = subLabels.Length;
   float num = (position.width - (float) (length - 1) * 2f) / (float) length;
   Rect position1 = new Rect(position);
   position1.width = num;
   float labelWidth1 = EditorGUIUtility.labelWidth;
   int indentLevel = EditorGUI.indentLevel;
   EditorGUIUtility.labelWidth = labelWidth;
   EditorGUI.indentLevel = 0;
   for (int index = 0; index < subLabels.Length; ++index)
   {
     if (disabledMask != null)
       EditorGUI.BeginDisabledGroup(disabledMask[index]);
     EditorGUI.PropertyField(position1, valuesIterator, subLabels[index]);
     if (disabledMask != null)
       EditorGUI.EndDisabledGroup();
     position1.x += num + 2f;
     valuesIterator.NextVisible(false);
   }
   EditorGUIUtility.labelWidth = labelWidth1;
   EditorGUI.indentLevel = indentLevel;
 }