Example #1
0
        protected override void OnExpandedGUI(WorldStampCreator parent)
        {
            if (EditorGUILayoutX.IndentedButton("Reset"))
            {
                ResetMask(parent.Template.Bounds, parent.Template.Terrain);
            }
            var hCreator = parent.GetCreator <HeightmapDataCreator>();
            var zLevel   = hCreator.ZeroLevel * parent.Template.Bounds.size.y;
            var width    = Mathf.Clamp(parent.Template.Bounds.size.y.ToString().Length * 16, 32, 64);

            if (_fillHeight.x == _fillHeight.y)
            {
                _fillHeight.y = _fillHeight.x + 0.001f;
            }
            _fillHeight = new Vector2(Mathf.Clamp(_fillHeight.x, -zLevel, parent.Template.Bounds.size.y - zLevel), Mathf.Clamp(_fillHeight.y, -zLevel, parent.Template.Bounds.size.y - zLevel));
            EditorGUILayout.BeginHorizontal();
            _fillHeight.x = EditorGUILayout.FloatField(_fillHeight.x, GUILayout.Width(width));
            EditorGUILayout.MinMaxSlider(ref _fillHeight.x, ref _fillHeight.y, -zLevel, parent.Template.Bounds.size.y - zLevel);
            _fillHeight.y = EditorGUILayout.FloatField(_fillHeight.y, GUILayout.Width(width));
            //_fillHeight = new Vector2(Mathf.RoundToInt(_fillHeight.x), Mathf.RoundToInt(_fillHeight.y));
            if (GUILayout.Button("Fill Below Height"))
            {
                FillMaskFromMinY(parent.Template.Bounds, parent.Template.Terrain, hCreator.Heights, _fillHeight - Vector2.one * (hCreator.ZeroLevel * parent.Template.Bounds.size.y));
            }
            EditorGUILayout.EndHorizontal();
            if (EditorGUILayoutX.IndentedButton("Load From Texture"))
            {
                LoadFromTexture(parent);
            }
        }
Example #2
0
        public static object DrawGUI(object target, string label = "", Type targetType = null, FieldInfo fieldInfo = null, object context = null)
        {
#if UNITY_EDITOR
            if (targetType == null && target == null && fieldInfo == null)
            {
                Debug.LogError("Insufficient information to determine type.");
                return(null);
            }

            if (targetType == null)
            {
                targetType = target != null?target.GetType() : fieldInfo.FieldType;
            }

            var drawer = GetDrawer(targetType);
            if (context != null && drawer != null)
            {
                target = drawer.DrawGUI(target, label, targetType, fieldInfo, context);
            }
            else
            {
                if (target != null)
                {
                    var isInList      = context != null && typeof(IList).IsAssignableFrom(context.GetType());
                    var isUnityObject = typeof(UnityEngine.Object).IsAssignableFrom(targetType);
                    if (!isInList && !isUnityObject && !targetType.IsAssignableFrom(typeof(IList)) && !targetType.IsArray)
                    {
                        EditorGUILayout.BeginHorizontal();
                        if (string.IsNullOrEmpty(label) && fieldInfo != null)
                        {
                            label = fieldInfo.Name;
                        }
                        EditorGUILayout.LabelField(string.Format("{0} [{1}]", label, targetType));
                        if (GUILayout.Button(GenericEditor.DeleteContent, EditorStyles.label, GUILayout.Width(20)))
                        {
                            return(null);
                        }
                        EditorGUILayout.EndHorizontal();
                    }

                    if (fieldInfo != null)
                    {
                        //Debug.Log(string.Format("FieldInfo for {0} wasn't null, so increased IndentLevel from {1} to {2}", fieldInfo.Name, EditorGUI.indentLevel, EditorGUI.indentLevel +1));
                        EditorGUI.indentLevel++;
                    }
                    var fields = GetFields(targetType);
                    foreach (var field in fields)
                    {
                        var subObj = field.GetValue(target);
                        subObj = DrawGUI(subObj, GetFriendlyName(field), subObj != null ? subObj.GetType() : field.FieldType, field, target);
                        field.SetValue(target, subObj);
                    }
                    if (fieldInfo != null)
                    {
                        //Debug.Log(string.Format("FieldInfo for {0} wasn't null, so decreased IndentLevel from {1} to {2}", fieldInfo.Name, EditorGUI.indentLevel, EditorGUI.indentLevel -1));
                        EditorGUI.indentLevel--;
                    }
                }
                else
                {
                    EditorGUILayout.BeginHorizontal();
                    EditorGUILayout.LabelField(label);
                    if (targetType.IsAbstract || targetType.IsInterface)
                    {
                        EditorGUILayoutX.DerivedTypeSelectButton(targetType, (o) =>
                        {
                            fieldInfo.SetValue(context, o);
                        }
                                                                 );
                    }
                    else if (EditorGUILayoutX.IndentedButton("Add " + targetType.Name))
                    {
                        target = Activator.CreateInstance(targetType);
                    }
                    EditorGUILayout.EndHorizontal();
                }
            }

            var unityObj = target as Object;
            if (!Application.isPlaying && unityObj)
            {
                EditorUtility.SetDirty(unityObj);
                EditorSceneManager.MarkAllScenesDirty();
            }
#endif
            return(target);
        }
Example #3
0
        private void DoTreesSection()
        {
            WorldStamp singleInstance = targets.Length == 1 ? target as WorldStamp : null;
            bool       canWrite       = !singleInstance || singleInstance.Data.Trees.Count > 0;

            DoHeader("Trees", ref _treesExpanded, _treesEnabled, canWrite);
            if (_treesExpanded)
            {
                EditorGUI.indentLevel++;
                if (!canWrite)
                {
                    EditorGUILayout.HelpBox("No Trees in Stamp", MessageType.Info);
                }
                if (targets.Length > 1)
                {
                    EditorGUILayout.HelpBox("Can't Edit Multiple Tree Ignores", MessageType.Info);
                }
                else
                {
                    var stamp = target as WorldStamp;

                    if (stamp.Data.Trees.Count > 0 && (stamp.Data.TreePrototypeCache == null || stamp.Data.TreePrototypeCache.Count == 0))
                    {
                        stamp.Data.TreePrototypeCache = new List <GameObject>();
                        foreach (var tree in stamp.Data.Trees)
                        {
                            if (!stamp.Data.TreePrototypeCache.Contains(tree.Prototype))
                            {
                                stamp.Data.TreePrototypeCache.Add(tree.Prototype);
                            }
                        }
                    }

                    for (var i = 0; i < stamp.Data.TreePrototypeCache.Count; ++i)
                    {
                        var prototype = stamp.Data.TreePrototypeCache[i];
                        if (prototype == null)
                        {
                            continue;
                        }

                        var ignored = stamp.IgnoredTrees.Contains(prototype);
                        GUILayout.BeginHorizontal();
                        GUI.color = ignored ? Color.red : Color.green;
                        var newPicked = (GameObject)EditorGUILayout.ObjectField(prototype, typeof(GameObject), false);
                        if (newPicked != null && newPicked != prototype)
                        {
                            prototype = newPicked;
                            EditorUtility.SetDirty(stamp);
                            var prefab = PrefabUtility.GetPrefabObject(stamp);
                            if (prefab)
                            {
                                EditorUtility.SetDirty(prefab);
                            }
                        }
                        if (EditorGUILayoutX.IndentedButton(ignored ? "Unmute" : "Mute"))
                        {
                            if (stamp.IgnoredTrees.Contains(prototype))
                            {
                                stamp.IgnoredTrees.Remove(prototype);
                            }
                            else
                            {
                                stamp.IgnoredTrees.Add(prototype);
                            }
                        }
                        GUILayout.EndHorizontal();
                    }
                    GUI.color = Color.white;
                }
                EditorGUILayout.PropertyField(_removeTrees, new GUIContent("Remove Existing Trees"));
                GUI.enabled = canWrite;
                EditorGUILayout.PropertyField(_stencilTrees);
                GUI.enabled = true;
                EditorGUI.indentLevel--;
            }
        }
Example #4
0
        protected override IList DrawGUIInternal(IList target, string label = "", Type targetType = null,
                                                 FieldInfo fieldInfo        = null,
                                                 object context             = null)
        {
            var expandedKey = fieldInfo != null ? fieldInfo.Name : context + "list";
            var listType    = targetType.IsArray ? targetType.GetElementType() : targetType.GetGenericArguments()[0];
            ListGenericUIAttribute listAttribute = fieldInfo != null?fieldInfo.GetAttribute <ListGenericUIAttribute>() : null;

            if (!GenericEditor.ExpandedFieldCache.ContainsKey(expandedKey))
            {
                GenericEditor.ExpandedFieldCache[expandedKey] = false;
            }
            if (fieldInfo != null)
            {
                GenericEditor.ExpandedFieldCache[expandedKey] =
                    EditorGUILayout.Foldout(GenericEditor.ExpandedFieldCache[expandedKey], fieldInfo.Name, EditorStyles.boldFont);
            }

            if (fieldInfo == null || GenericEditor.ExpandedFieldCache[expandedKey])
            {
                for (var i = 0; i < target.Count; i++)
                {
                    EditorGUI.indentLevel++;
                    var o = target[i];
                    if (!GenericEditor.ExpandedFieldCache.ContainsKey(expandedKey + i))
                    {
                        GenericEditor.ExpandedFieldCache[expandedKey + i] = false;
                    }

                    if (typeof(UnityEngine.Object).IsAssignableFrom(listType))
                    {
                        EditorGUILayout.BeginHorizontal();
                        o = EditorGUILayout.ObjectField((UnityEngine.Object)o, listType, true);
                        if (GUILayout.Button(GenericEditor.DeleteContent, EditorStyles.label, GUILayout.Width(20)))
                        {
                            if (targetType.IsArray)
                            {
                                target = ((Array)target).Remove(i);
                            }
                            else
                            {
                                target.RemoveAt(i);
                            }
                            break;
                        }
                        EditorGUILayout.EndHorizontal();
                    }
                    else
                    {
                        EditorGUILayout.BeginHorizontal();

                        string objectLabel = "NULL";
                        if (o != null)
                        {
                            objectLabel = o.ToString();
                        }
                        EditorGUILayout.BeginHorizontal(GUILayout.ExpandWidth(true));
                        GenericEditor.ExpandedFieldCache[expandedKey + i] =
                            EditorGUILayout.Foldout(GenericEditor.ExpandedFieldCache[expandedKey + i], objectLabel);
                        EditorGUILayout.EndHorizontal();

                        if (o != null && typeof(IHelpLinkProvider).IsAssignableFrom(listType))
                        {
                            var helpURL = (o as IHelpLinkProvider).HelpURL;
                            if (!string.IsNullOrEmpty(helpURL))
                            {
                                EditorExtensions.HelpButton(helpURL);
                            }
                        }

                        if (GUILayout.Button(GenericEditor.DeleteContent, EditorStyles.label, GUILayout.Width(20)))
                        {
                            target.RemoveAt(i);
                            break;
                        }

                        var enableToggle = o as IShowEnableToggle;
                        if (enableToggle != null)
                        {
                            var lastIndent = EditorGUI.indentLevel;
                            EditorGUI.indentLevel       = 0;
                            enableToggle.Editor_Enabled = EditorGUILayout.Toggle(GUIContent.none, enableToggle.Editor_Enabled, GUILayout.Width(20));
                            EditorGUI.indentLevel       = lastIndent;
                        }

                        EditorGUILayout.EndHorizontal();

                        if (GenericEditor.ExpandedFieldCache[expandedKey + i])
                        {
                            if (o != null)
                            {
                                o = GenericEditor.DrawGUI(o, "", o.GetType(), fieldInfo, target);
                            }
                            else
                            {
                                o = GenericEditor.DrawGUI(null, "Null", listType, fieldInfo, target);
                            }
                        }
                    }
                    target[i] = o;
                    EditorGUI.indentLevel--;
                    EditorExtensions.Seperator();
                }

                if (!typeof(UnityEngine.Object).IsAssignableFrom(listType) && (listType.IsAbstract || listType.IsInterface || (fieldInfo != null && listAttribute != null && listAttribute.AllowDerived)))
                {
                    EditorGUILayoutX.DerivedTypeSelectButton(listType, (o) => target.Add(o));
                }
                else if (EditorGUILayoutX.IndentedButton("Add " + listType.Name))
                {
                    if (typeof(UnityEngine.Object).IsAssignableFrom(listType))
                    {
                        if (targetType.IsArray)
                        {
                            target = ((Array)target).Add(null);
                        }
                        else
                        {
                            target.Add(null);
                        }
                    }
                    else
                    {
                        var newInstance = Activator.CreateInstance(listType);
                        if (newInstance != null && !newInstance.Equals(null))
                        {
                            if (targetType.IsArray)
                            {
                                target = ((Array)target).Add(newInstance);
                            }
                            else
                            {
                                target.Add(newInstance);
                            }
                        }
                    }
                }
            }
            return(target);
        }
Example #5
0
        private void DoSplatsSection()
        {
            WorldStamp singleInstance = targets.Length == 1 ? target as WorldStamp : null;
            bool       canWrite       = !singleInstance ||
                                        (singleInstance.Data.SplatData != null && singleInstance.Data.SplatData.Count > 0);

            DoHeader("Splats", ref _splatsExpanded, _splatsEnabled, canWrite);
            if (_splatsExpanded)
            {
                EditorGUI.indentLevel++;
                if (!canWrite)
                {
                    EditorGUILayout.HelpBox("No Splats in Stamp", MessageType.Info);
                }
                GUI.enabled = canWrite;
                EditorGUILayout.PropertyField(_stencilSplats);
                EditorGUILayout.PropertyField(_splatBlendMode);

                if (targets.Length > 1)
                {
                    EditorGUILayout.HelpBox("Can't Edit Multiple Splat Ignores", MessageType.Info);
                }
                else
                {
                    var stamp = target as WorldStamp;
                    foreach (var keyValuePair in stamp.Data.SplatData)
                    {
                        var splatWrapper = keyValuePair.Wrapper;
                        var ignored      = stamp.IgnoredSplats.Contains(splatWrapper);
                        GUILayout.BeginHorizontal();
                        GUI.color = ignored ? Color.red : Color.green;
                        var newPicked = (SplatPrototypeWrapper)EditorGUILayout.ObjectField(splatWrapper, typeof(SplatPrototypeWrapper), false);
                        if (newPicked != null && newPicked != splatWrapper)
                        {
                            keyValuePair.Wrapper = newPicked;
                            EditorUtility.SetDirty(stamp);
                            var prefab = PrefabUtility.GetPrefabObject(stamp);
                            if (prefab)
                            {
                                EditorUtility.SetDirty(prefab);
                            }
                        }
                        if (EditorGUILayoutX.IndentedButton(ignored ? "Unmute" : "Mute"))
                        {
                            if (stamp.IgnoredSplats.Contains(splatWrapper))
                            {
                                stamp.IgnoredSplats.Remove(splatWrapper);
                            }
                            else
                            {
                                stamp.IgnoredSplats.Add(splatWrapper);
                            }
                        }
                        GUILayout.EndHorizontal();
                    }
                    GUI.color = Color.white;
                }
                GUI.enabled = true;
                EditorGUI.indentLevel--;
            }
        }