Пример #1
0
        public void OnEnable()
        {
            //autoFSMEvent init;
            //List<FsmEvent> EventList = FsmEvent.EventList;
            PrefabVODB.Reload();
            string path;
            IList  o;

            string[] excelFileIDTypes = new string[]
            { ExcelFileIDType.Npc, ExcelFileIDType.Monster, ExcelFileIDType.Collection };
            foreach (string excelFileIDType in excelFileIDTypes)
            {
                path = EditorConfigUtils.GetPrifix(excelFileIDType);
                o    = FileHelper.GetAMF(path, false) as IList;
                if (o == null)
                {
                    continue;
                }
                List <ExcelRefVO> list = new List <ExcelRefVO>();
                foreach (Dictionary <string, object> item in o)
                {
                    ExcelRefVO excelVO = new ExcelRefVO();
                    excelVO.id         = item.Get <string>("id");
                    excelVO.name       = item.Get <string>("name");
                    excelVO.uri        = item.Get <string>("uri");
                    excelVO.prefabPath = PrefabVODB.GetPath(excelVO.uri);
                    list.Add(excelVO);
                }
                ExcelIDSelecterDrawer.Fill(excelFileIDType, list);
            }

            path = EditorConfigUtils.GetPrifix(ExcelFileIDType.Map);
            o    = FileHelper.GetAMF(path, false) as IList;
            if (o != null)
            {
                foreach (Dictionary <string, object> item in o)
                {
                    ExcelMapVO excelVO = new ExcelMapVO();
                    excelVO.id   = item.Get <string>("id");
                    excelVO.name = item.Get <string>("name");
                    excelVO.uri  = item.Get <string>("uri");
                    ExcelIDSelecterDrawer.AddMapItem(excelVO);
                }
            }

            this.titleContent = new GUIContent("SceneEditor");


            allReleaseScenes.Clear();
            scenesGenericMenu = new GenericMenu();
            string[] fileList = new string[0];
            if (Directory.Exists("Assets/Prefabs/scene"))
            {
                fileList = Directory.GetFiles("Assets/Prefabs/scene", "*.unity", SearchOption.AllDirectories);
            }
            foreach (string file in fileList)
            {
                allReleaseScenes.Add(file);
                string fileName = Path.GetFileNameWithoutExtension(file);
                scenesGenericMenu.AddItem(new GUIContent(fileName), false, (object item) =>
                {
                    string scenePath = item.ToString();
                    if (File.Exists(scenePath))
                    {
                        Scene scene = EditorSceneManager.OpenScene(scenePath, OpenSceneMode.Single);
                        CheckSceneInfo(true);
                        _selectedSceneCfgMode = SceneCFGMode.SceneSettings;
                        Repaint();
                    }
                }, file);
            }

            SceneView.duringSceneGui += OnSceneGUI;
            EditorApplication.playModeStateChanged -= playmodeStateChanged;
            EditorApplication.playModeStateChanged += playmodeStateChanged;
        }
Пример #2
0
        protected override void drawSceneGUI()
        {
            foreach (PointVO pointVo in previewObjects.Keys)
            {
                GameObject go = previewObjects[pointVo];
                if (go != null)
                {
                    go.SetRendererEnabledRecursive(false);
                }
            }


            int   len   = mTarget.list.Count;
            Color color = Handles.color;

            for (int i = 0; i < len; i++)
            {
                PointVO pointCFG = mTarget.list[i];

                if (pointCFG.type == PointType.Entrance)
                {
                    color = Color.green;
                }
                else if (pointCFG.type == PointType.Entrance)
                {
                    color = Color.blue;
                }
                else if (pointCFG.type == PointType.Exit)
                {
                    color = Color.red;
                }
                else if (pointCFG.type == PointType.Npc)
                {
                    color = Color.yellow;
                }
                else
                {
                    color = Color.white;
                }

                if (i == selectedIndex)
                {
                    color.a = 1.0f;
                }
                else
                {
                    color.a = 0.5f;
                }

                Handles.color = color;
                EditorGUI.BeginChangeCheck();
                float   size   = HandleUtility.GetHandleSize(pointCFG.position) * controlSize;
                Vector3 newPos = Handles.FreeMoveHandle(pointCFG.position, Quaternion.identity, size / 2, Vector3.zero,
                                                        Handles.SphereHandleCap);

                Vector3    hitPos = pointCFG.position;
                RaycastHit hit;
                if (Physics.Linecast(pointCFG.position, pointCFG.position - new Vector3(0, 100, 0), out hit))
                {
                    hitPos = hit.point;
                }
                Handles.color = Color.black;
                Handles.DrawLine(pointCFG.position, hitPos);
                Handles.color = color;

                Quaternion q = Quaternion.Euler(0, pointCFG.euler, 0);
                Handles.ArrowHandleCap(0, pointCFG.position, q, size, Event.current.type);

                if (EditorGUI.EndChangeCheck())
                {
                    selectedIndex = i;
                    Undo.RegisterCompleteObjectUndo(mTarget, "move Points");
                    pointCFG.position = newPos;
                }

                Color oldColor = GUI.color;
                GUI.color = Color.white;
                string id = pointCFG.id;
                if (string.IsNullOrEmpty(id))
                {
                    id = "#" + (i + 1) + "#";
                }

                Handles.Label(newPos, id);
                GUI.color = oldColor;

                if (ShowPreview && pointCFG.type == PointType.Npc && string.IsNullOrEmpty(id) == false)
                {
                    GameObject go = null;
                    if (previewObjects.TryGetValue(pointCFG, out go) == false)
                    {
                        ExcelRefVO vo = ExcelIDSelecterDrawer.Get(ExcelFileIDType.Npc, id);
                        if (vo != null)
                        {
                            go = vo.CreateByPrefab();
                            if (go)
                            {
                                previewObjects.Add(pointCFG, go);
                            }
                        }
                    }

                    if (go != null)
                    {
                        go.transform.position = newPos;
                        go.transform.rotation = q;
                        go.SetRendererEnabledRecursive(true);
                    }
                }
            }
        }
Пример #3
0
        private void itemCreateHandle(SerializedProperty list, SerializedProperty item, int index)
        {
            EditorGUILayout.BeginVertical("box");
            EditorGUILayout.BeginHorizontal();

            Color oldColor = GUI.contentColor;

            bool isCurrent = selectedIndex == index;

            if (isCurrent)
            {
                GUI.contentColor = Color.yellow;
            }
            EditorGUI.indentLevel++;

            SerializedProperty idProperty    = item.FindPropertyRelative("id");
            SerializedProperty pointProperty = item.FindPropertyRelative("position");
            string             id            = idProperty.stringValue;

            EditorGUI.BeginChangeCheck();
            bool b = EditorGUILayout.Foldout(isCurrent, "m" + (index + 1) + ":" + id);

            EditorGUI.indentLevel--;
            if (EditorGUI.EndChangeCheck())
            {
                if (b)
                {
                    selectedIndex = index;
                    EditorUtils.GotoScenePoint(pointProperty.vector3Value);
                }
                else
                {
                    selectedIndex = -1;
                }
            }
            SerializedProperty typeProperty = item.FindPropertyRelative("type");

            EditorGUILayout.PropertyField(typeProperty, GUIContent.none, GUILayout.Width(60));
            b &= showButtons(list, index, itemControlStyle);
            EditorGUILayout.EndHorizontal();
            if (b)
            {
                EditorGUILayout.PropertyField(idProperty);
                EditorGUILayout.BeginHorizontal();

                EditorGUILayout.PropertyField(pointProperty);
                if (GUILayout.Button("Raycast", EditorStyles.miniButton, GUILayout.Width(60)))
                {
                    Vector3 v = pointProperty.vector3Value;
                    v.y += 50f;
                    Ray        ray = new Ray(v, Vector3.down);
                    RaycastHit hit;
                    if (Physics.Raycast(ray, out hit, 100, Physics.AllLayers, QueryTriggerInteraction.Ignore))
                    {
                        Undo.RegisterCompleteObjectUndo(mTarget, "rayCast");
                        pointProperty.vector3Value = hit.point;
                    }
                }
                EditorGUILayout.EndHorizontal();
                EditorGUILayout.PropertyField(item.FindPropertyRelative("euler"));

                if (string.IsNullOrEmpty(id) == false)
                {
                    ExcelRefVO vo = ExcelIDSelecterDrawer.Get(ExcelFileIDType.Npc, id);
                    if (vo != null)
                    {
                        if (GUILayout.Button("View", EditorStyles.miniButton))
                        {
                            ExcelIDSelecterDrawer.ShowView(vo);
                        }
                    }
                }
            }

            GUI.contentColor = oldColor;
            EditorGUILayout.EndVertical();
        }
Пример #4
0
        protected override void drawSceneGUI()
        {
            foreach (TeamMonsterCFG cfg in previewObjects.Keys)
            {
                GameObject go = previewObjects[cfg];
                if (go != null)
                {
                    go.SetRendererEnabledRecursive(false);
                }
            }

            List <TeamCFG> list = mTarget.list;

            if (list == null || list.Count <= 0)
            {
                return;
            }

            Event e = Event.current;

            Vector3 position;
            int     len = list.Count;

            bool isCurrentZoom = false;

            Color color   = Color.red;
            float centerY = 0;

            int[] zoomHosControl = new int[len];
            for (int i = 0; i < len; i++)
            {
                isCurrentZoom = zoomIndex == i;
                TeamCFG teamCfg = list[i];
                Rect    rect    = teamCfg.rect;
                position = new Vector3(rect.center.x, 0, rect.center.y);

                if (isCurrentZoom == false)
                {
                    color.a = 0.3f;
                }
                else
                {
                    color.a = 1.0f;
                }
                Handles.color = color;
                GUI.color     = color;

                Vector3 rectCenter = new Vector3(rect.x, 0, rect.y);

                verts[0] = new Vector3(rect.x - rect.width / 2f, centerY, rect.y - rect.height / 2f);
                verts[1] = new Vector3(rect.x + rect.width / 2f, centerY, rect.y - rect.height / 2f);
                verts[2] = new Vector3(rect.x + rect.width / 2f, centerY, rect.y + rect.height / 2f);
                verts[3] = new Vector3(rect.x - rect.width / 2f, centerY, rect.y + rect.height / 2f);

                Handles.DrawSolidRectangleWithOutline(verts, rectSolideColor, Color.gray);

                float   size = HandleUtility.GetHandleSize(rectCenter) * controlSize;
                Vector3 newPos;

                newPos = Handles.FreeMoveHandle(rectCenter, Quaternion.identity, size / 2, Vector3.zero,
                                                (controlID, p, rotation, s, evenType) =>
                {
                    zoomHosControl[i] = controlID;
                    Handles.DotHandleCap(controlID, p, rotation, s, evenType);
                });

                if (GUIUtility.hotControl == zoomHosControl[i])
                {
                    if (GUIUtility.hotControl != 0 && e.type == EventType.Repaint)
                    {
                        zoomIndex = i;
                        Repaint();
                    }
                }

                if (rectCenter != newPos)
                {
                    Undo.RecordObject(mTarget, "TeamMove");
                    rect.x       = newPos.x;
                    rect.y       = newPos.z;
                    teamCfg.rect = rect;
                }

                int   jLen = teamCfg.list.Count;
                int[] monsterHosControl = new int[jLen];
                for (int j = 0; j < jLen; j++)
                {
                    TeamMonsterCFG monsterCfg = teamCfg.list[j];
                    position = rectCenter + monsterCfg.position;

                    size   = HandleUtility.GetHandleSize(position) * controlSize;
                    newPos = Handles.FreeMoveHandle(position, Quaternion.identity, size, Vector3.zero,
                                                    (int controlID, Vector3 pos, Quaternion rotation, float s, EventType et) =>
                    {
                        monsterHosControl[j] = controlID;
                        if (j == monsterIndex && isCurrentZoom)
                        {
                            Handles.color = Color.green;
                        }
                        Handles.SphereHandleCap(controlID, pos, rotation, s, et);
                        Handles.color = color;
                    });

                    if (GUIUtility.hotControl == monsterHosControl[j] && GUIUtility.hotControl != 0 && isCurrentZoom)
                    {
                        if (e.type == EventType.Repaint)
                        {
                            monsterIndex = j;
                            Repaint();
                        }
                    }

                    Quaternion q = Quaternion.Euler(0, monsterCfg.euler, 0);
                    Handles.ArrowHandleCap(0, position, q, size, Event.current.type);

                    Vector3    hitPos = new Vector3(monsterCfg.position.x, 0, monsterCfg.position.z);
                    RaycastHit hit;
                    if (Physics.Linecast(monsterCfg.position, monsterCfg.position - new Vector3(0, 100, 0), out hit))
                    {
                        hitPos = hit.point;
                    }
                    Handles.color = Color.black;
                    Handles.DrawLine(monsterCfg.position, hitPos);
                    Handles.color = color;

                    if (position != newPos && isCurrentZoom)
                    {
                        Undo.RegisterCompleteObjectUndo(mTarget, "MonsterMove");
                        monsterCfg.position = newPos - rectCenter;
                    }

                    Color oldColor = GUI.color;
                    GUI.color = Color.white;
                    string monsterId = monsterCfg.id;
                    if (string.IsNullOrEmpty(monsterId))
                    {
                        monsterId = "#" + (j + 1) + "#";
                    }
                    else if (ShowPreview)
                    {
                        GameObject go = null;
                        if (previewObjects.TryGetValue(monsterCfg, out go) == false)
                        {
                            ExcelRefVO vo = ExcelIDSelecterDrawer.Get(ExcelFileIDType.Monster, monsterId);
                            if (vo != null)
                            {
                                go = vo.CreateByPrefab();
                                if (go)
                                {
                                    previewObjects.Add(monsterCfg, go);
                                }
                            }
                        }
                        if (go != null)
                        {
                            go.transform.position = newPos;
                            go.transform.rotation = q;
                            go.SetRendererEnabledRecursive(true);
                        }
                    }
                    Handles.Label(position, monsterId);
                    GUI.color = oldColor;
                }

                GUI.color = Color.white;
                Handles.Label(rectCenter, "Team" + (i + 1), headStyle.zoomText);
            }
            GUI.color = Color.white;
        }