public void ShapeAdd(AreaWorldModMagicValueType shape) { Vector3 pos = UnityEngine.Random.onUnitSphere * 0.2f; AreaWorldModMagicValue mod = new AreaWorldModMagicValue(); mod.position = pos; mod.rotation = Quaternion.identity; mod.myType = shape; switch (shape) { case AreaWorldModMagicValueType.Sphere: mod.SetValuesAsSphere(0.5f); break; case AreaWorldModMagicValueType.Capsule: mod.SetValuesAsCapsule(0.5f, 2f); break; case AreaWorldModMagicValueType.Cuboid: mod.SetValuesAsCuboid(0.5f, 0.5f, 0.5f); break; } mod.id = allMods.Count; mod.container = this; mod.SetDirty(); allMods.Add(mod); RecalculateBounds(); }
public override void OnInspectorGUI() { serializedObject.Update(); AreaWorldMod currentTarget = (target as AreaWorldMod); Event e = Event.current; EditorGUILayout.PropertyField(priority, priorityContent); //this one is important EditorGUI.BeginChangeCheck(); bool useAA = EditorGUILayout.ToggleLeft(useAdvancedAreaContent, currentTarget.useAdvancedArea); if (EditorGUI.EndChangeCheck()) { //SceneView.RepaintAll(); currentTarget.SetUseAdvancedArea(useAA); } if (currentTarget.useAdvancedArea) { EditorGUILayout.PropertyField(advancedArea); EditorGUI.BeginChangeCheck(); bool startState = EditorGUILayout.ToggleLeft(cellUsabilityStateContent, currentTarget.cellUsabilityState); if (EditorGUI.EndChangeCheck()) { currentTarget.SetCellsState(startState); } } else { EditorGUILayout.PropertyField(areaInt); } UITools.Line(); EditorGUILayout.PropertyField(drawGizmos, drawGizmosContent); if (drawGizmos.boolValue) { EditorGUILayout.PropertyField(drawGizmosAlpha, drawGizmosAlphaContent); EditorGUILayout.PropertyField(drawBounds, drawBoundsContent); } UITools.Line(); EditorGUILayout.PropertyField(mode, modeContent); UITools.Line(); //EditorGUILayout.PropertyField(serializedObject.FindProperty(filterString)); //SmallUITools.Line(); drawShapeList = EditorGUILayout.Foldout(drawShapeList, new GUIContent("Shape List")); if (drawShapeList) { GUILayout.BeginHorizontal(); EditorGUI.BeginChangeCheck(); editShape = EditorGUILayout.ToggleLeft("Edit Shape", editShape, GUILayout.MaxWidth(80)); if (EditorGUI.EndChangeCheck()) { Repaint(); SceneView.RepaintAll(); } curShape = (AreaWorldModMagicValueType)EditorGUILayout.EnumPopup(curShape); bool flag = false; if (GUILayout.Button("Add", GUILayout.MaxHeight(14))) { Undo.RecordObject(target, "Add"); currentTarget.ShapeAdd(curShape); flag = true; } if (flag) { SceneView.RepaintAll(); } GUILayout.EndHorizontal(); Rect lastRect = GUILayoutUtility.GetLastRect(); float lastHeight = lastRect.y + lastRect.height; SerializedProperty allMods = serializedObject.FindProperty(allModsString); mouseOver = IndexedFlag.nope; cursorInsideSellectedArea = false; for (int i = 0; i < allMods.arraySize; i++) { SerializedProperty arrayElement = allMods.GetArrayElementAtIndex(i); float height = EditorGUI.GetPropertyHeight(arrayElement) + 2; Rect boxRect = new Rect(0, lastHeight, Screen.width, height); Color curColor = GUI.color; if (boxRect.Contains(e.mousePosition)) { mouseOver = new IndexedFlag(true, i); GUI.color = colorSellectionMouseOver; cursorInsideSellectedArea = true; if (e.type == EventType.MouseDown) { if (e.button == 1) { int tempI = i; onShapeClick = new GenericMenu(); if (tempI > 0) { onShapeClick.AddItem(new GUIContent("Move Up"), false, () => { currentTarget.ShapeDecreaseValueID(tempI); mouseOver = IndexedFlag.nope; Repaint(); SceneView.RepaintAll(); }); } if (tempI < allMods.arraySize - 1) { onShapeClick.AddItem(new GUIContent("Move Down"), false, () => { currentTarget.ShapeIncreaseValueID(tempI); mouseOver = IndexedFlag.nope; Repaint(); SceneView.RepaintAll(); }); } onShapeClick.AddItem(new GUIContent("Copy"), false, () => { currentTarget.ShapeCopyAt(tempI); mouseOver = IndexedFlag.nope; Repaint(); SceneView.RepaintAll(); }); onShapeClick.AddItem(new GUIContent("Remove"), false, () => { currentTarget.ShapeRemoveAt(tempI); mouseOver = IndexedFlag.nope; Repaint(); SceneView.RepaintAll(); }); onShapeClick.ShowAsContext(); } } } GUI.Box(boxRect, string.Empty); GUI.color = curColor; EditorGUILayout.PropertyField(arrayElement); lastHeight += height; } if (cursorInsideSellectedArea) { Repaint(); SceneView.RepaintAll(); } if (cursorInsideSellectedArea != tempFlagCursorInsideSellectedArea) { tempFlagCursorInsideSellectedArea = cursorInsideSellectedArea; Repaint(); SceneView.RepaintAll(); } } UITools.Line(); drawGameObjectList = EditorGUILayout.Foldout(drawGameObjectList, new GUIContent("GameObject List")); //Rect lastRec = GUILayoutUtility.GetLastRect(); if (drawGameObjectList) { if (GUILayout.Button("Update Childs")) { currentTarget.RebuildChilds(false); } TextAnchor curBoxAnchor = GUI.skin.box.alignment; GUI.skin.box.alignment = TextAnchor.MiddleLeft; foreach (var item in currentTarget.childsAndBounds.Keys) { GUILayout.Box(item.name, GUILayout.MinWidth(200)); } GUI.skin.box.alignment = curBoxAnchor; } if (currentTarget.CheckDirty()) { Repaint(); SceneView.RepaintAll(); } if (serializedObject.ApplyModifiedProperties()) { currentTarget.DirtyAll(); } }