示例#1
0
        public override void OnInspectorGUI()
        {
            LocationType oldType = (LocationType)typeProp.enumValueIndex;
            LocationType newType = (LocationType)EditorGUILayout.EnumPopup("Type", oldType);

            if (newType != oldType)
            {
                if (oldType == LocationType.Group)
                {
                    if (EditorUtility.DisplayDialog("Change Location Type", changeGroupMessage, "Yes", "No"))
                    {
                        subLocsListProp.ClearArray();
                    }
                    else
                    {
                        newType = LocationType.Group;
                    }
                }
                typeProp.enumValueIndex = (int)newType;
            }

            if (newType == LocationType.Area)
            {
                EditorGUILayout.PropertyField(sizeProp);
            }

            if (newType == LocationType.Group)
            {
                List <string> copyNames;
                if (CheckSubLocations(subLocsListProp, out copyNames))
                {
                    EditorGUILayout.HelpBox("Sub Locations Have Repeated Names: \n" + RepeatedNamesString(copyNames) + "\nSubLocations marked red will not be saved...", MessageType.Error);
                }
                EditorGUILayout.PropertyField(subLocsProp);
                LocationPainter.OnGUI( );
            }

            serializedObject.ApplyModifiedProperties();

            EditorUtility.SetDirty(target);
        }
示例#2
0
        void DrawGroupSceneGUI(SerializedProperty subLocsListProp)
        {
            float screenW = SceneView.lastActiveSceneView.position.width;
            float screenH = SceneView.lastActiveSceneView.position.height;

            for (int i = 0; i < subLocsListProp.arraySize; i++)
            {
                SerializedProperty s = subLocsListProp.GetArrayElementAtIndex(i);

                bool selected = s.FindPropertyRelative("selected").boolValue;
                bool hovered  = s.FindPropertyRelative("hovered").boolValue;

                if (!selected && !hovered)
                {
                    continue;
                }

                SerializedProperty posProp = s.FindPropertyRelative("position");

                Vector3 pos       = posProp.vector3Value;
                Vector3 screenPos = SceneView.lastActiveSceneView.camera.WorldToViewportPoint(pos);

                Handles.BeginGUI();
                GUIContent lbl       = new GUIContent(s.FindPropertyRelative("name").stringValue);
                float      w         = GUITools.label.CalcSize(lbl).x;
                Rect       labelRect = new Rect(screenPos.x * screenW - w * .5f, (1 - screenPos.y) * screenH - EditorGUIUtility.singleLineHeight, w, EditorGUIUtility.singleLineHeight);
                GUITools.Box(labelRect, hovered ? GUITools.white : colorSolid);
                GUI.Label(labelRect, lbl);
                Handles.EndGUI();

                if (selected || hovered)
                {
                    posProp.vector3Value = Handles.PositionHandle(pos, Quaternion.Euler(0, s.FindPropertyRelative("rotation").floatValue, 0));
                }
            }

            LocationPainter.OnSceneGUI(subLocsListProp, GetHashCode());
        }