Beispiel #1
0
        private void OnGroupAssetGUI()
        {
            if (target == null)
            {
                FocusOn(null, SelectionType.Map);
                return;
            }
            MapGroupAsset groupAsset = target as MapGroupAsset;

            DrawPreview();
            GUILayout.Label(groupAsset.groupName, Prefs.nameStyle);
            groupAsset.information = EditorGUILayout.TextArea(groupAsset.information, Prefs.informationStyle);
            if (GUILayout.Button("", Prefs.mapAssetBackgroundStyle, GUILayout.ExpandHeight(true)))
            {
                GUI.FocusControl("");
            }
            GUILayout.BeginHorizontal(Prefs.mapAssetBackgroundStyle, GUILayout.Height(28));
            {
                GUILayout.FlexibleSpace();
                if (!groupAsset.baked && GUILayout.Button("烘焙", GUILayout.Width(60)))
                {
                    MapGroupAssetEditor.BakeGroupAsset(groupAsset);
                }
                if (GUILayout.Button("加载组", GUILayout.Width(60)))
                {
                    MapGroupAssetEditor.LoadGroup(MapAssetManager.CurrentAsset, MapSystem.currentGroupIndex); FocusOn(MapSystem.groupList[MapSystem.currentGroupIndex], SelectionType.Group);
                }
            }
            GUILayout.EndHorizontal();
        }
Beispiel #2
0
        private void OnGroupGUI()
        {
            MapGroup group = target as MapGroup;

            DrawPreview(true);

            if (group == null)
            {
                GUILayout.Label("当前组为空", Prefs.informationStyle);

                if (GUILayout.Button("", Prefs.mapAssetBackgroundStyle, GUILayout.ExpandHeight(true)))
                {
                    GUI.FocusControl("");
                }
                GUILayout.BeginHorizontal(Prefs.mapAssetBackgroundStyle, GUILayout.Height(28));
                {
                    GUILayout.FlexibleSpace();
                    if (GUILayout.Button("新建组", GUILayout.Width(60)))
                    {
                        MapGroupAssetEditor.NewEmptyGroup(MapSystem.currentGroupIndex); FocusOn(MapSystem.groupList[MapSystem.currentGroupIndex], SelectionType.Group);
                    }
                    if (MapAssetManager.CurrentAsset != null && GUILayout.Button("加载组", GUILayout.Width(60)))
                    {
                        MapGroupAssetEditor.LoadGroup(MapAssetManager.CurrentAsset, MapSystem.currentGroupIndex); FocusOn(MapSystem.groupList[MapSystem.currentGroupIndex], SelectionType.Group);
                    }
                }
                GUILayout.EndHorizontal();
            }
            else
            {
                EditableNameField(group);

                if (GUILayout.Button("组序号:" + group.index, Prefs.mapAssetBackgroundStyle, GUILayout.ExpandHeight(true)))
                {
                    GUI.FocusControl("");
                }
                GUILayout.BeginHorizontal(Prefs.mapAssetBackgroundStyle, GUILayout.Height(28));
                {
                    GUILayout.FlexibleSpace();
                    if (GUILayout.Button("保存组", GUILayout.Width(60)))
                    {
                        MapGroupAssetEditor.SaveGroup(group); FocusOn(MapSystem.groupList[MapSystem.currentGroupIndex], SelectionType.Group);
                    }
                    if (GUILayout.Button("卸载组", GUILayout.Width(60)))
                    {
                        FocusOn(null, SelectionType.Group); MapGroupAssetEditor.UnLoadGroup(group);
                    }
                    if (MapAssetManager.CurrentAsset != null && GUILayout.Button("加载组", GUILayout.Width(60)))
                    {
                        MapGroupAssetEditor.LoadGroup(MapAssetManager.CurrentAsset, MapSystem.currentGroupIndex); FocusOn(MapSystem.groupList[MapSystem.currentGroupIndex], SelectionType.Group);
                    }
                }
                GUILayout.EndHorizontal();
            }
        }
Beispiel #3
0
 /// <summary>
 /// 存储Group
 /// </summary>
 public static void SaveGroup(MapGroup group)
 {
     if (ContainsAsset(group.groupName))
     {
         if (EditorUtility.DisplayDialog("温馨小提示", "场景组已存在,是否覆盖?", "覆盖", "取消"))
         {
             MapGroupAssetEditor.SaveToAsset(group, GetGroupAssetByName(group.groupName));
             group.dirty = false;
         }
     }
     else
     {
         CreateGroupAsset(group);
     }
 }
        private void OnGUI()
        {
            toolbarSelected = GUILayout.Toolbar(toolbarSelected, toolbarTitle, Prefs.toolbarStyle);

            if (toolbarSelected == 0)
            {
                //物体

                if (PrefabInformation.Count == 0)
                {
                    //大小为空
                    GUILayout.Label("……", Prefs.mapAssetBackgroundStyle, GUILayout.ExpandHeight(true));
                }
                else
                {
                    //selection list
                    scollVector = GUILayout.BeginScrollView(scollVector);
                    {
                        List <string> assetNameList = new List <string>();
                        for (int i = 0; i < PrefabInformation.Count; i++)
                        {
                            assetNameList.Add(PrefabInformation.Keys[i].name);
                        }
                        EditorGUI.BeginChangeCheck();
                        prefabSelected = GUILayout.SelectionGrid(prefabSelected, assetNameList.ToArray(), 1, Prefs.mapAssetBackgroundStyle, GUILayout.Height(27 * PrefabInformation.Count));
                        if (EditorGUI.EndChangeCheck())
                        {
                            MapInspector.FocusOn(CurrentPrefab, MapInspector.SelectionType.Prefab);
                        }

                        GUILayout.Label("", Prefs.mapAssetBackgroundStyle, GUILayout.ExpandHeight(true));
                    }
                    GUILayout.EndScrollView();

                    //function
                    GameObject cp = CurrentPrefab;
                    GUILayout.BeginHorizontal(Prefs.mapAssetBackgroundStyle, GUILayout.Height(28));
                    {
                        GUILayout.FlexibleSpace();
                        if (GUILayout.Button("删除", GUILayout.Width(60)))
                        {
                            DeletePrefab(cp); prefabSelected--; MapInspector.FocusOn(CurrentPrefab, MapInspector.SelectionType.Prefab);
                        }
                    }
                    GUILayout.EndHorizontal();


                    //drag the prefab out
                    switch (Event.current.type)
                    {
                    case EventType.MouseDown:
                        tempPrefabInstance = PrefabUtility.InstantiatePrefab(CurrentPrefab) as GameObject;
                        Debug.Log(tempPrefabInstance);
                        break;

                    case EventType.MouseDrag:
                        if (tempPrefabInstance == null)
                        {
                            break;
                        }
                        Vector3 prefabPos = Vector3.zero;
                        if (mouseOverWindow == null)
                        {
                            validPos = false;
                        }
                        else if (mouseOverWindow.GetType() == typeof(MapManager))
                        {
                            MapManager mapManager = mouseOverWindow as MapManager;
                            Vector2    guiPos     = Event.current.mousePosition + position.position - mapManager.position.position;
                            prefabPos = mapManager.GetElementWorldPos(guiPos, 0);
                            validPos  = true;
                        }
                        else if (mouseOverWindow.GetType() == typeof(SceneView))
                        {
                            SceneView sv = SceneView.lastActiveSceneView;
                            Handles.SetCamera(SceneView.lastActiveSceneView.camera);
                            Vector2 guiPos = Event.current.mousePosition + new Vector2(position.xMin - sv.position.xMin, position.yMax - sv.position.yMax);
                            Ray     ray    = HandleUtility.GUIPointToWorldRay(guiPos);
                            float   yRate  = ray.origin.y / ray.direction.y;
                            prefabPos = new Vector3(ray.origin.x - ray.direction.x * yRate, 0, ray.origin.z - ray.direction.z * yRate);
                            validPos  = true;
                        }
                        else
                        {
                            validPos = false;
                        }
                        tempPrefabInstance.transform.position = prefabPos;
                        break;

                    case EventType.MouseUp:
                        DestroyImmediate(tempPrefabInstance);
                        break;

                    case EventType.Ignore:
                        if (validPos)
                        {
                            MapManager.SetMapObject(tempPrefabInstance);
                        }
                        else
                        {
                            DestroyImmediate(tempPrefabInstance);
                        }
                        break;
                    }
                }
            }
            else
            {
                //地图组预设
                if (MapGroupAssets.Count == 0)
                {
                    //大小为空
                    GUILayout.Label("……", Prefs.mapAssetBackgroundStyle, GUILayout.ExpandHeight(true));
                }
                else
                {
                    //selection list
                    scollVector = GUILayout.BeginScrollView(scollVector);
                    {
                        List <string> assetNameList = new List <string>();
                        for (int i = 0; i < MapGroupAssets.Count; i++)
                        {
                            assetNameList.Add(MapGroupAssets[i].groupName + (MapGroupAssets[i].baked ? "" : Prefs.mapAssetUnbakedStateMark));
                        }
                        EditorGUI.BeginChangeCheck();
                        mapAssetSelected = GUILayout.SelectionGrid(mapAssetSelected, assetNameList.ToArray(), 1, Prefs.mapAssetBackgroundStyle, GUILayout.Height(27 * MapGroupAssets.Count));
                        if (EditorGUI.EndChangeCheck())
                        {
                            MapInspector.FocusOn(CurrentAsset, MapInspector.SelectionType.GroupAsset);
                        }

                        GUILayout.Label("", Prefs.mapAssetBackgroundStyle, GUILayout.ExpandHeight(true));
                    }
                    GUILayout.EndScrollView();

                    //function
                    MapGroupAsset mga = CurrentAsset;
                    GUILayout.BeginHorizontal(Prefs.mapAssetBackgroundStyle, GUILayout.Height(28));
                    {
                        GUILayout.FlexibleSpace();
                        if (!mga.baked && GUILayout.Button("烘焙", GUILayout.Width(60)))
                        {
                            MapGroupAssetEditor.BakeGroupAsset(mga);
                        }
                        if (GUILayout.Button("删除", GUILayout.Width(60)))
                        {
                            MapGroupAssetEditor.DeleteGroupAsset(mga); mapAssetSelected = 0; MapInspector.FocusOn(CurrentAsset, MapInspector.SelectionType.GroupAsset);
                        }
                    }
                    GUILayout.EndHorizontal();
                }
            }
        }