示例#1
0
        public static GameLayers CreateLayerContainer()
        {
            GameLayers asset = ScriptableObject.CreateInstance<GameLayers>();

            AssetDatabase.CreateAsset(asset, "Assets/Resources/GameLayers.asset");
            AssetDatabase.SaveAssets();

            EditorUtility.FocusProjectWindow();

            Selection.activeObject = asset;

            return asset;
        }
示例#2
0
        void OnGUI()
        {
            //TODO: Create an object field and have the user set the game layers object through that instead of it auto-creating below

            if(layersObject == null)
            {
                layersObject = GameLayers.CreateLayerContainer();
            }

            Rect newRect = CalculateWindowDimensions();
            if(LayerManagerWindow.repositionWindowOnce)
                this.position = new Rect(GUIUtility.GUIToScreenPoint(Event.current.mousePosition), new Vector2(newRect.width, newRect.height));

            LayerManagerWindow.repositionWindowOnce = false;

            EditorGUILayout.LabelField("Game Layers:", EditorStyles.wordWrappedLabel);
            EditorGUILayout.LabelField("", EditorStyles.wordWrappedLabel);
            GUILayout.Space(5);

            SerializedObject manager = new SerializedObject(AssetDatabase.LoadAllAssetsAtPath(LayerAssetPath)[0]);
            SerializedProperty layersProp = manager.FindProperty("layers");

            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.LabelField("Layer", GUILayout.MaxWidth(100));
            EditorGUILayout.LabelField("Current", EditorStyles.label, GUILayout.MaxWidth(200));
            EditorGUILayout.LabelField("Default", EditorStyles.label, GUILayout.MaxWidth(200));
            EditorGUILayout.EndHorizontal();

            //allow editing of the project's layers
            scrollPos = EditorGUILayout.BeginScrollView(scrollPos);
            for(int i = 8; i <= 31; i++)
            {
                SerializedProperty sp = layersProp.GetArrayElementAtIndex(i);


                EditorGUILayout.BeginHorizontal();
                EditorGUILayout.LabelField("Layer " + i, GUILayout.MaxWidth(100));
                EditorGUILayout.PropertyField(sp, GUIContent.none, GUILayout.Width(180));
                if(layersObject.Layers[i].Length > 0)
                    EditorGUILayout.LabelField("" + layersObject.Layers[i], EditorStyles.label, GUILayout.MaxWidth(200));
                EditorGUILayout.EndHorizontal();
            }
            EditorGUILayout.EndScrollView();
            manager.ApplyModifiedProperties();

            GUILayout.Space(5);

            //Set any default layers to the Game Default layers
            if(GUILayout.Button("Add Game defaults (will not replace)"))
            {
                for(int i = 8; i <= 31; i++)
                {
                    SerializedProperty sp = layersProp.GetArrayElementAtIndex(i);

                    if(sp.stringValue.Length > 0)
                        continue;

                    if(layersObject.Layers[i].Length > 0)
                        sp.stringValue = layersObject.Layers[i];
                }
                manager.ApplyModifiedProperties();
            }

            //Set any default layers to the Game Default layers
            if(GUILayout.Button("Set to Game defaults"))
            {
                for(int i = 8; i <= 31; i++)
                {
                    SerializedProperty sp = layersProp.GetArrayElementAtIndex(i);

                    if(layersObject.Layers[i].Length > 0)
                        sp.stringValue = layersObject.Layers[i];
                }
                manager.ApplyModifiedProperties();
            }

            if(GUILayout.Button("Close"))
            {
                this.Close();
            }

            Event e = Event.current;
            switch(e.type)
            {
                case EventType.KeyDown:
                    {
                        if(Event.current.keyCode == (KeyCode.Escape))
                        {
                            this.Close();
                        }
                        break;
                    }
            }
        }