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);
                    }
                }
            }
        }
Exemple #2
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;
        }