private static Dictionary <string, string> ChangeLuaPrefab(List <LuaBindItem> bindItems) { if (bindItems == null) { return(null); } Dictionary <string, string> nameDic = new Dictionary <string, string>(); foreach (var item in bindItems) { if (ScriptsHelper.IsIgnored(item.go)) { continue; } string tag = ""; if (m_BindTypeDic.TryGetValue(item.bindType, out tag)) { var data = ScriptsHelper.ParseName(item.go); data.tags.Add(tag); Selection.activeGameObject = item.go; HierarchyEditor.AddTag(tag); nameDic[item.variableName] = ScriptsHelper.GetFieldName(data.name, tag); } } return(nameDic); }
private static Dictionary <string, string> ChangeCSharpPrefab(FieldInfo[] infos, object obj) { if (infos == null) { return(null); } Dictionary <string, string> nameDic = new Dictionary <string, string>(); foreach (var item in infos) { var val = item.GetValue(obj); GameObject go = null; if (val is Component) { var com = val as Component; go = com.gameObject; } else if (val is MonoBehaviour) { var mono = val as MonoBehaviour; go = mono.gameObject; } else if (val is GameObject) { go = val as GameObject; } if (go != null) { var prefabStage = PrefabStageUtility.GetPrefabStage(go); if (prefabStage != null) { if (ScriptsHelper.IsIgnored(go)) { continue; } var type = item.FieldType; foreach (var t in Const.m_ComponentDict) { if (t.Value == type) { var data = ScriptsHelper.ParseName(go); string tag = t.Key; data.tags.Add(tag); Selection.activeGameObject = go; HierarchyEditor.AddTag(tag); nameDic[item.Name] = ScriptsHelper.GetFieldName(data.name, tag); break; } } } } } return(nameDic); }
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) { const float sizeX = 18f; const float sizeY = 16f; var prop = property.FindPropertyRelative("component"); var component = prop.objectReferenceValue; var newComponent = EditorGUI.ObjectField(position, label, component, typeof(WindowComponent), allowSceneObjects: true); if (newComponent != component) { prop.objectReferenceValue = newComponent; property.serializedObject.ApplyModifiedProperties(); } HierarchyEditor.DrawLabel(new Rect(position.x + position.width - sizeX - 54f, position.y, 54f, sizeY), HierarchyEditor.colors.linkers, "PROXY"); }
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) { const float sizeX = 76f; const float sizeY = 16f; var indent = EditorGUI.indentLevel * 15f; var propertyPosition = new Rect(position.x, position.y, position.width - sizeX, position.height); var labelPosition = new Rect(propertyPosition.x + propertyPosition.width - indent, propertyPosition.y, sizeX + indent, propertyPosition.height); if (ME.EditorUtilities.IsPrefab((property.serializedObject.targetObject as Component).gameObject) == true) { var oldState = GUI.enabled; GUI.enabled = false; EditorGUI.PropertyField(propertyPosition, property, label, true); GUI.enabled = oldState; } else { EditorGUI.PropertyField(propertyPosition, property, label, true); } HierarchyEditor.DrawLabel(new Rect(labelPosition.x + labelPosition.width - sizeX, labelPosition.y, sizeX, sizeY), HierarchyEditor.colors.layouts, "SCENE EDIT"); }
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) { const float iconSizeX = 30f; const float iconSizeY = 16f; const float asyncSizeX = 58f; const float asyncSizeY = 16f; const float asyncToggleSizeX = 18f; var controlTypeSizeXMax = 140f; var controlTypeSizeX = 0f; var attr = PropertyExtensions.GetAttribute <ResourceParametersAttribute>(this); var controlType = property.FindPropertyRelative("controlType"); var values = System.Enum.GetValues(typeof(UnityEngine.UI.Windows.ResourceAuto.ControlType)); var names = System.Enum.GetNames(typeof(UnityEngine.UI.Windows.ResourceAuto.ControlType)); var items = new List <byte>(); var itemNames = new List <string>(); if (attr != null) { for (int i = 0; i < values.Length; ++i) { var value = (byte)values.GetValue(i); if (value == 0) { continue; } if (((byte)attr.drawOnly & value) != 0) { controlTypeSizeX += controlTypeSizeXMax / values.Length; items.Add(value); itemNames.Add(names[i]); } } } else { for (int i = 0; i < values.Length; ++i) { var value = (byte)values.GetValue(i); if (value == 0) { continue; } controlTypeSizeX += controlTypeSizeXMax / values.Length; items.Add(value); itemNames.Add(names[i]); } } var propertyPosition = new Rect(position.x, position.y, position.width - iconSizeX - asyncSizeX - controlTypeSizeX + 30f, position.height); var labelPosition = new Rect(position.x + propertyPosition.width - iconSizeX - 18f, propertyPosition.y, iconSizeX, iconSizeY); var asyncRectLabel = new Rect(position.x + propertyPosition.width, position.y, asyncSizeX - asyncToggleSizeX, asyncSizeY); var asyncRect = new Rect(asyncRectLabel.x + asyncRectLabel.width, position.y, asyncToggleSizeX, asyncSizeY); var controlTypeRect = new Rect(asyncRect.x + asyncRect.width, position.y, controlTypeSizeX, asyncSizeY); var tempObject = property.FindPropertyRelative("tempObject"); /*var _obj = PropertyExtensions.GetTargetObjectOfProperty(property); * var _res = _obj as ResourceAuto; * if (_res != null) { * * if (tempObject.objectReferenceValue == null) { * * _res.ResetToDefault(); * * } else { * * _res.Validate(tempObject.objectReferenceValue); * * } * * }*/ /*PropertyExtensions.GetTargetObjectsOfProperty<ResourceAuto>(property, (res) => { * * if (res != null) { * * if (tempObject.objectReferenceValue == null) { * * res.ResetToDefault(); * * } else { * * res.Validate(tempObject.objectReferenceValue); * * } * * } * * });*/ var oldObj = tempObject.objectReferenceValue; var newObj = EditorGUI.ObjectField(propertyPosition, label, oldObj, typeof(Object), allowSceneObjects: false); if (oldObj != newObj) { tempObject.objectReferenceValue = newObj; property.serializedObject.ApplyModifiedProperties(); PropertyExtensions.GetTargetObjectsOfProperty <ResourceAuto>(property, (res) => { if (res != null) { if (newObj == null) { res.ResetToDefault(); } else { res.Validate(newObj); } } else { Debug.LogWarning("ResourceBase cannot be found"); } }); } EditorGUI.BeginDisabledGroup(tempObject.objectReferenceValue == null); var asyncToggle = property.FindPropertyRelative("async"); if (GUI.Button(asyncRectLabel, new GUIContent("Async", "Loads Object Asynchronously"), EditorStyles.miniButtonLeft) == true) { asyncToggle.boolValue = !asyncToggle.boolValue; } var oldColor = GUI.color; GUI.color = (asyncToggle.boolValue == false ? oldColor : Color.green); asyncToggle.boolValue = GUI.Toggle(asyncRect, asyncToggle.boolValue, string.Empty, EditorStyles.miniButtonRight); GUI.color = oldColor; EditorGUI.EndDisabledGroup(); for (int i = 0; i < items.Count; ++i) { var k = i; var width = controlTypeRect.width / items.Count; var value = items[i]; var enumValue = controlType.intValue; var isOn = (enumValue & value) != 0; isOn = GUI.Toggle(new Rect(controlTypeRect.x + (k * width), controlTypeRect.y, width, controlTypeRect.height), isOn, new GUIContent(itemNames[i], "Event when you want to initialize/deinitialize this resource"), (k == 0 ? EditorStyles.miniButtonLeft : (i == items.Count - 1 ? EditorStyles.miniButtonRight : EditorStyles.miniButtonMid))); if (isOn == true) { enumValue |= value; } else { enumValue &= ~value; } controlType.intValue = enumValue; } //controlType.enumValueIndex = (int)(UnityEngine.UI.Windows.ResourceAuto.ControlType)EditorGUI.EnumMaskField(controlTypeRect, (UnityEngine.UI.Windows.ResourceAuto.ControlType)(controlType.enumValueIndex >= 0 ? controlType.enumValueIndex : 0)); HierarchyEditor.DrawLabel(labelPosition, HierarchyEditor.colors.transitions, "RES"); }
public void Fill(List <Object> objects, FillMode fillMode = FillMode.Default) { objects = new List <Object>(objects); if (fillMode == FillMode.Add) { components.RemoveAll(item => item == null); foreach (var component in components) { if (!objects.Contains(component)) { objects.Add(component); } } } Dispose(); components = objects; folouts.Clear(); foreach (var component in components) { Foldout folout = new Foldout(string.Format("{0}", component.GetType().Name)); folout.Value = components.Count == 1 ? true : false; folout.name = folout.Title; folouts.Add(folout); folout.imageElement.image = EditorGUIUtility.ObjectContent(component, component.GetType()).image; folout.headerElement.RegisterCallback <MouseUpEvent>((evt) => { if (evt.button == 1) { Rect rect = new Rect(folout.headerElement.layout); rect.position = evt.mousePosition; HierarchyEditor.DisplayObjectContextMenu(rect, component, 0); evt.StopPropagation(); } }); Label objectName = new Label(string.Format(" [{0}]", component.name)); objectName.StyleTextColor(objectNameColor); objectName.RegisterCallback <MouseUpEvent>((evt) => { if (evt.button == 0) { EditorGUIUtility.PingObject(component); Selection.activeObject = component; evt.StopPropagation(); } }); folout.headerElement.Add(objectName); Image remove = new Image(); remove.image = EditorGUIUtility.IconContent("winbtn_win_close").image; remove.StyleSize(13, 13); remove.StylePosition(Position.Absolute); remove.StyleRight(8); remove.StyleAlignSelf(Align.Center); remove.RegisterCallback <MouseUpEvent>((evt) => { if (evt.button == 0) { if (component != null) { components.Remove(component); } else { components.RemoveAll(item => item == null); } Fill(new List <Object>(components)); evt.StopPropagation(); } }); folout.headerElement.Add(remove); bool isMat = component is Material; Editor editor = null; if (isMat) { editor = MaterialEditor.CreateEditor(component) as MaterialEditor; } else { editor = Editor.CreateEditor(component); } VisualElement inspector = editor.CreateInspectorGUI(); if (inspector == null) { inspector = new IMGUIContainer(() => { bool tempState = EditorGUIUtility.wideMode; float tempWidth = EditorGUIUtility.labelWidth; EditorGUIUtility.wideMode = true; if (component is Transform) { EditorGUIUtility.labelWidth = 64; } if (editor.target != null) { if (isMat) { MaterialEditor maEditor = editor as MaterialEditor; EditorGUILayout.BeginVertical(); if (maEditor.PropertiesGUI()) { maEditor.PropertiesChanged(); } EditorGUILayout.EndVertical(); } else { editor.OnInspectorGUI(); } objectName.StyleTextColor(objectNameColor); } else { objectName.StyleTextColor(Color.red); EditorGUILayout.HelpBox("Reference not found.", MessageType.Info); } EditorGUIUtility.wideMode = tempState; EditorGUIUtility.labelWidth = tempWidth; }); } inspector.style.marginLeft = 16; inspector.style.marginRight = 2; inspector.style.marginTop = 4; folout.Add(inspector); editors.Add(editor); scrollView.Add(folout); if (isMat) { var preview = new IMGUIContainer(() => { editor.DrawPreview(new Rect(0, 0, inspector.layout.size.x, Mathf.Clamp(inspector.layout.width / 2, 64, 200))); }); preview.StyleMarginTop(4); preview.StretchToParentWidth(); inspector.RegisterCallback <GeometryChangedEvent>((callback) => { preview.StyleHeight(Mathf.Clamp(inspector.layout.width / 2, 64, 200)); }); preview.StylePosition(Position.Relative); preview.name = "Material Preview"; folout.Add(preview); } } Repaint(); }
public static void Draw(Rect position, SerializedProperty property, GUIContent label) { /*if (Application.isPlaying == false) { * * LocalizationSystem.TryToLoadCache(); * * }*/ //property.serializedObject.Update(); var keyProperty = property.FindPropertyRelative("key"); var parametersCountProperty = property.FindPropertyRelative("parameters"); var formatWithDeclensionProperty = property.FindPropertyRelative("formatWithDeclension"); if (keyProperty != null && parametersCountProperty != null && formatWithDeclensionProperty != null) { //GUILayout.BeginHorizontal(); { var labelWidth = EditorGUIUtility.labelWidth; var offset = new Vector2(-23f - 100f - labelWidth, -7f - 16f); var indent = EditorGUI.indentLevel * 16f; GUI.Label(new Rect(position.x + indent, position.y, labelWidth - indent, position.height), label); var buttonRect = new Rect(position.x + labelWidth, position.y, position.width - labelWidth, position.height); var keyValue = keyProperty.stringValue; var keyFull = (string.IsNullOrEmpty(keyValue) == true ? string.Empty : string.Format("[{0}] {1} ({2})", parametersCountProperty.intValue, keyValue, LocalizationSystem.Get(keyValue, LocalizationSystem.DEFAULT_EDITOR_LANGUAGE))); if (GUI.Button(buttonRect, keyFull, EditorStyles.textField) == true) { var rect = position; Vector2 vector = GUIUtility.GUIToScreenPoint(new Vector2(position.x, position.y)); rect.x = vector.x; rect.y = vector.y; var popup = new Popup() { title = "Localization Keys", screenRect = new Rect(rect.x + labelWidth + offset.x, rect.y + rect.height + offset.y, rect.width - labelWidth - offset.x, 200f), searchText = keyProperty.stringValue, separator = '|' }; popup.Item("None", () => { keyProperty.serializedObject.Update(); parametersCountProperty.serializedObject.Update(); formatWithDeclensionProperty.serializedObject.Update(); keyProperty.stringValue = string.Empty; parametersCountProperty.intValue = 0; formatWithDeclensionProperty.boolValue = false; formatWithDeclensionProperty.serializedObject.ApplyModifiedProperties(); parametersCountProperty.serializedObject.ApplyModifiedProperties(); keyProperty.serializedObject.ApplyModifiedProperties(); EditorUtility.SetDirty(keyProperty.serializedObject.targetObject); }); foreach (var key in LocalizationSystem.GetKeys()) { var finalKey = key; var finalKeyFull = string.Format("{0} <color=grey>({1})</color>", finalKey, LocalizationSystem.Get(finalKey, LocalizationSystem.DEFAULT_EDITOR_LANGUAGE)); popup.Item(finalKeyFull, () => { formatWithDeclensionProperty.serializedObject.Update(); parametersCountProperty.serializedObject.Update(); keyProperty.serializedObject.Update(); keyProperty.stringValue = finalKey; parametersCountProperty.intValue = LocalizationSystem.GetParametersCount(finalKey, LocalizationSystem.DEFAULT_EDITOR_LANGUAGE); formatWithDeclensionProperty.boolValue = LocalizationSystem.IsNeedToFormatWithDeclension(finalKey, LocalizationSystem.DEFAULT_EDITOR_LANGUAGE); formatWithDeclensionProperty.serializedObject.ApplyModifiedProperties(); parametersCountProperty.serializedObject.ApplyModifiedProperties(); keyProperty.serializedObject.ApplyModifiedProperties(); EditorUtility.SetDirty(keyProperty.serializedObject.targetObject); }); } popup.Show(); } var textFieldRect = buttonRect; //GUILayoutUtility.GetLastRect(); EditorGUIUtility.AddCursorRect(textFieldRect, MouseCursor.Text); const float sizeX = 32f; const float sizeY = 16f; HierarchyEditor.DrawLabel(new Rect(textFieldRect.x + textFieldRect.width - sizeX, textFieldRect.y, sizeX, sizeY), HierarchyEditor.colors.screens, "LOC"); if (LocalizationSystem.ContainsKey(keyProperty.stringValue) == false) { HierarchyEditor.DrawLabel(new Rect(textFieldRect.x + textFieldRect.width - sizeX - 54f, textFieldRect.y, 54f, sizeY), HierarchyEditor.colors.error, "NO KEY"); } } //GUILayout.EndHorizontal(); } //property.serializedObject.ApplyModifiedProperties(); }
public static void Draw(Rect position, SerializedProperty property, GUIContent label) { if (Application.isPlaying == false) { GameDataSystem.TryToLoadCache(); } //property.serializedObject.Update(); var keyProperty = property.FindPropertyRelative("key"); if (keyProperty != null) { //GUILayout.BeginHorizontal(); { var labelWidth = EditorGUIUtility.labelWidth; var offset = new Vector2(-23f - 100f - labelWidth, -7f - 16f); var indent = EditorGUI.indentLevel * 16f; GUI.Label(new Rect(position.x + indent, position.y, labelWidth - indent, position.height), label); var buttonRect = new Rect(position.x + labelWidth, position.y, position.width - labelWidth, position.height); var style = ME.Utilities.CacheStyle("GameDataKeyDrawer.TextStyle", "inputField", (name) => { var _style = new GUIStyle(EditorStyles.textField); _style.richText = true; return(_style); }); var keyValue = keyProperty.stringValue; var keyFull = string.Format("[<color=green><b>{1}</b></color>] {0}", keyValue, GameDataSystem.Get(keyValue, GameDataSystem.DEFAULT_EDITOR_VERSION)); if (GUI.Button(buttonRect, keyFull, style) == true) { var rect = position; Vector2 vector = GUIUtility.GUIToScreenPoint(new Vector2(position.x, position.y)); rect.x = vector.x; rect.y = vector.y; var popup = new Popup() { title = "GameData Keys", screenRect = new Rect(rect.x + labelWidth + offset.x, rect.y + rect.height + offset.y, rect.width - labelWidth - offset.x, 200f), searchText = keyProperty.stringValue, separator = '|' }; popup.ItemByPath("None", () => { keyProperty.serializedObject.Update(); keyProperty.stringValue = string.Empty; keyProperty.serializedObject.ApplyModifiedProperties(); EditorUtility.SetDirty(keyProperty.serializedObject.targetObject); }); foreach (var key in GameDataSystem.GetKeys()) { var finalKey = key; var finalKeyFull = string.Format("{0} <color=grey>({1})</color>", finalKey, GameDataSystem.Get(finalKey, GameDataSystem.DEFAULT_EDITOR_VERSION)); popup.ItemByPath(finalKeyFull, () => { keyProperty.serializedObject.Update(); keyProperty.stringValue = finalKey; keyProperty.serializedObject.ApplyModifiedProperties(); EditorUtility.SetDirty(keyProperty.serializedObject.targetObject); }); } popup.Show(); } var textFieldRect = buttonRect; //GUILayoutUtility.GetLastRect(); EditorGUIUtility.AddCursorRect(textFieldRect, MouseCursor.Text); const float sizeX = 32f; const float sizeY = 16f; HierarchyEditor.DrawLabel(new Rect(textFieldRect.x + textFieldRect.width - sizeX, textFieldRect.y, sizeX, sizeY), HierarchyEditor.colors.layoutElements, "GD"); if (GameDataSystem.ContainsKey(keyProperty.stringValue) == false) { HierarchyEditor.DrawLabel(new Rect(textFieldRect.x + textFieldRect.width - sizeX - 54f, textFieldRect.y, 54f, sizeY), HierarchyEditor.colors.error, "NO KEY"); } else { HierarchyEditor.DrawLabel(new Rect(textFieldRect.x + textFieldRect.width - sizeX - 54f, textFieldRect.y, 54f, sizeY), HierarchyEditor.colors.components, GameDataSystem.DEFAULT_EDITOR_VERSION.ToString()); } } //GUILayout.EndHorizontal(); } //property.serializedObject.ApplyModifiedProperties(); }
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) { const float iconSizeX = 30f; const float iconSizeY = 16f; const float asyncSizeX = 58f; const float asyncSizeY = 16f; const float asyncToggleSizeX = 18f; const float controlTypeSizeX = 140f; var propertyPosition = new Rect(position.x, position.y, position.width - iconSizeX - asyncSizeX - controlTypeSizeX + 30f, position.height); var labelPosition = new Rect(position.x + propertyPosition.width - iconSizeX - 18f, propertyPosition.y, iconSizeX, iconSizeY); var asyncRectLabel = new Rect(position.x + propertyPosition.width, position.y, asyncSizeX - asyncToggleSizeX, asyncSizeY); var asyncRect = new Rect(asyncRectLabel.x + asyncRectLabel.width, position.y, asyncToggleSizeX, asyncSizeY); var controlTypeRect = new Rect(asyncRect.x + asyncRect.width, position.y, controlTypeSizeX, asyncSizeY); var tempObject = property.FindPropertyRelative("tempObject"); EditorGUI.ObjectField(propertyPosition, tempObject, label); EditorGUI.BeginDisabledGroup(tempObject.objectReferenceValue == null); var asyncToggle = property.FindPropertyRelative("async"); if (GUI.Button(asyncRectLabel, new GUIContent("Async", "Loads Object Asynchronously"), EditorStyles.miniButtonLeft) == true) { asyncToggle.boolValue = !asyncToggle.boolValue; } var oldColor = GUI.color; GUI.color = (asyncToggle.boolValue == false ? oldColor : Color.green); asyncToggle.boolValue = GUI.Toggle(asyncRect, asyncToggle.boolValue, string.Empty, EditorStyles.miniButtonRight); GUI.color = oldColor; EditorGUI.EndDisabledGroup(); var attr = PropertyExtensions.GetAttribute <ResourceParametersAttribute>(this); var controlType = property.FindPropertyRelative("controlType"); var values = System.Enum.GetValues(typeof(UnityEngine.UI.Windows.ResourceBase.ControlType)); var names = System.Enum.GetNames(typeof(UnityEngine.UI.Windows.ResourceBase.ControlType)); var items = new List <byte>(); var itemNames = new List <string>(); if (attr != null) { for (int i = 0; i < values.Length; ++i) { var value = (byte)values.GetValue(i); if (value == 0) { continue; } if (((byte)attr.drawOnly & value) != 0) { items.Add(value); itemNames.Add(names[i]); } } } else { for (int i = 0; i < values.Length; ++i) { var value = (byte)values.GetValue(i); if (value == 0) { continue; } items.Add(value); itemNames.Add(names[i]); } } for (int i = 0; i < items.Count; ++i) { var k = i; var width = controlTypeRect.width / items.Count; var value = items[i]; var enumValue = controlType.intValue; var isOn = (enumValue & value) != 0; isOn = GUI.Toggle(new Rect(controlTypeRect.x + (k * width), controlTypeRect.y, width, controlTypeRect.height), isOn, new GUIContent(itemNames[i], "Event when you want to initialize/deinitialize this resource"), (k == 0 ? EditorStyles.miniButtonLeft : (i == items.Count - 1 ? EditorStyles.miniButtonRight : EditorStyles.miniButtonMid))); if (isOn == true) { enumValue |= value; } else { enumValue &= ~value; } controlType.intValue = enumValue; } //controlType.enumValueIndex = (int)(UnityEngine.UI.Windows.ResourceBase.ControlType)EditorGUI.EnumMaskField(controlTypeRect, (UnityEngine.UI.Windows.ResourceBase.ControlType)(controlType.enumValueIndex >= 0 ? controlType.enumValueIndex : 0)); HierarchyEditor.DrawLabel(labelPosition, HierarchyEditor.colors.transitions, "RES"); if (GUI.changed == true) { EditorUtility.SetDirty(asyncToggle.serializedObject.targetObject); } }