예제 #1
0
    public override void ShowAuxInfo()
    {
        Handles.BeginGUI();
        var re = SceneView.lastActiveSceneView.position;

        GUILayout.BeginArea(new Rect(0, re.height - 100, re.width, 100), EditorStyles.objectFieldThumb);//EditorStyles.toolbarButton);
        {
            var          objs   = ResourceCenter.Instance.prefabObjects;
            var          thumbs = ResourceCenter.Instance.thumbnails;
            GUIContent[] gc     = new GUIContent[objs.Length];
            for (int i = 0; i < gc.Length; ++i)
            {
                gc[i] = new GUIContent(thumbs[i]);
            }
            selectedObjectIndex = GUILayout.SelectionGrid(
                selectedObjectIndex,
                gc,
                gc.Length,
                EditorStyles.objectFieldThumb,//EditorStyles.toolbarButton,
                GUILayout.Width(200),
                GUILayout.Height(100));
        }
        GUILayout.EndArea();
        Handles.EndGUI();
        Vector3 mapsize = MapModifier.Instance.MapSize;// / (cm.paintedgridlength / cm.unitlength);

        MapAux.DrawMapCellsDotted(cm.center, mapsize, cm.unitlength, Color.yellow);
        MapAux.DrawMapCells(cm.center, mapsize / (cm.paintedgridlength / cm.unitlength), cm.paintedgridlength, Color.blue);
        MapModifier.Instance.ShowGameObjectIndexInfo();
    }
예제 #2
0
    public override void ShowAuxInfo()
    {
        Vector3 mapsize = MapModifier.Instance.MapSize;

        MapAux.DrawMapCellsDotted(cm.center, mapsize, cm.unitlength, Color.yellow);
        MapAux.DrawMapCells(cm.center, mapsize / (cm.paintedgridlength / cm.unitlength), cm.paintedgridlength, Color.blue);
    }
예제 #3
0
    public override void DealWithEvent()
    {
        Event current   = Event.current;
        int   controlID = GUIUtility.GetControlID(FocusType.Passive);

        HandleUtility.AddDefaultControl(controlID);
        Vector3 collisionPos = MapModifier.Instance.CaculateCollisionPosFromGUIPoint(current.mousePosition);

        if (collisionPos.y == float.MaxValue)
        {
            return;
        }
        collisionPos = new Vector3(collisionPos.x, 0, collisionPos.z);
        Vector3 lefttopcenter = MapModifier.Instance.CaculateCellCenterByPos(collisionPos);
        int     lefttopindex  = MapModifier.Instance.CaculateIndexForPos(lefttopcenter);

        MapAux.ShowLabel(new Vector3(lefttopcenter.x + cm.unitlength, lefttopcenter.y, lefttopcenter.z + cm.unitlength), lefttopindex.ToString(), Color.black);

        Vector3 size = new Vector3(1, 0, 1);
        var     flag = MapModifier.Instance.CheckContainUnreachable(lefttopindex, size);

        if (flag)
        {
            Handles.color = Color.green;
        }
        else
        {
            Handles.color = Color.red;
        }
        Handles.DrawSolidDisc(lefttopcenter, Vector3.up, .5f);
        switch (current.type)
        {
        case EventType.mouseDown:
            if (current.button == 0)
            {
                if (flag == false)
                {
                    MapModifier.Instance.AddUnreachableIndex(lefttopindex);
                }
                else
                {
                    MapModifier.Instance.RemoveUnreachableIndex(lefttopindex);
                }
                current.Use();
            }
            else if (current.button == 1)
            {
                // Debug.Log(current.keyCode);
            }
            break;

        default:
            break;
        }
        SceneView.RepaintAll();
    }
예제 #4
0
    public override void DealWithEvent()
    {
        Event current   = Event.current;
        int   controlID = GUIUtility.GetControlID(FocusType.Passive);

        HandleUtility.AddDefaultControl(controlID);
        Vector3 collisionPos = MapModifier.Instance.CaculateCollisionPosFromGUIPoint(current.mousePosition);

        if (collisionPos.y == float.MaxValue)
        {
            return;
        }
        collisionPos = new Vector3(collisionPos.x, 0, collisionPos.z);
        Vector3 lefttopcenter = MapModifier.Instance.CaculateCellCenterByPos(collisionPos);
        Vector3 objectsize    = MapModifier.Instance.CaculateGameObjectSize(selectedObjectIndex);
        int     lefttopindex  = MapModifier.Instance.CaculateIndexForPos(lefttopcenter);
        int     biggridindex  = MapModifier.Instance.CaculatePaintedGridFromUnitIndex(lefttopindex);

        int[]   unitindexes       = MapModifier.Instance.CaculateUnitIndexesOfGrid(biggridindex);
        int     girdlefttopindex  = unitindexes[0];
        Vector3 girdlefttopcenter = MapModifier.Instance.TranselateIndexToPostion(girdlefttopindex);
        Vector3 buildcenter       = MapModifier.Instance.CaculateCreateGameObjectCenter(girdlefttopcenter, objectsize);

        MapAux.ShowLabel(new Vector3(lefttopcenter.x + cm.unitlength, lefttopcenter.y, lefttopcenter.z + cm.unitlength), biggridindex.ToString(), Color.black);

        var flag = MapModifier.Instance.CheckContainUnreachable(girdlefttopindex, objectsize);

        if (flag == true)
        {
            MapAux.DrawLines(girdlefttopcenter, objectsize, Color.red);
        }
        else
        {
            MapAux.DrawLines(girdlefttopcenter, objectsize, Color.green);
        }
        switch (current.type)
        {
        case EventType.mouseDown:
            if (current.button == 0 && (!flag))
            {
                MapModifier.Instance.AddObject(girdlefttopindex, buildcenter, selectedObjectIndex);
                MapModifier.Instance.AddNewItem(girdlefttopindex, objectsize, selectedObjectIndex);
                current.Use();
            }
            else if (current.button == 1)
            {
                // Debug.Log(current.keyCode);
            }
            break;

        default:
            break;
        }
        SceneView.RepaintAll();
    }
예제 #5
0
    // int cellIndex;
    //  int bigcellIndex;
    public override void ShowAuxInfo()
    {
        Vector3 mapsize = MapModifier.Instance.MapSize;

        MapAux.DrawMapCellsDotted(cm.center, mapsize, cm.unitlength, Color.yellow);
        MapAux.DrawMapCells(cm.center, mapsize / (cm.paintedgridlength / cm.unitlength), cm.paintedgridlength, Color.blue);
        foreach (var e in cm.unreachable)
        {
            Vector3 center = MapModifier.Instance.TranselateIndexToPostion(e);
            MapAux.DrawMapUnreachableArea(center, cm.unitlength, Color.red);
        }
    }
예제 #6
0
 public void ShowAreaFreeMoveHandles()
 {
     foreach (var e in cm.designerArea)
     {
         Handles.color = Color.green;
         Handles.CapFunction customfunc = Handles.CubeHandleCap;
         customfunc += HandleRecorder.RecordHandles;
         e.start     = Handles.FreeMoveHandle(e.start, Quaternion.identity, .5f, Vector3.zero, customfunc);
         HandleRecorder.CheckID(e);
         e.end = Handles.FreeMoveHandle(e.end, Quaternion.identity, .5f, Vector3.zero, customfunc);
         HandleRecorder.CheckID(e);
         MapAux.DrawRectHandles(e.start, e.end);
         var newstyle = new GUIStyle();
         newstyle.fontSize = 10;
         Handles.Label((e.start + e.end) / 2, e.id.ToString(), newstyle);
     }
 }
예제 #7
0
    public override void DealWithEvent()
    {
        Event current   = Event.current;
        int   controlID = GUIUtility.GetControlID(FocusType.Passive);

        HandleUtility.AddDefaultControl(controlID);
        Vector3 collisionPos = MapModifier.Instance.CaculateCollisionPosFromGUIPoint(current.mousePosition);

        if (collisionPos.y == float.MaxValue)
        {
            return;
        }
        collisionPos = new Vector3(collisionPos.x, 0, collisionPos.z);
        Vector3 lefttopcenter = MapModifier.Instance.CaculateCellCenterByPos(collisionPos);
        // Vector3 objectsize = Vector3.zero;//MapModifier.Instance.CaculateGameObjectSize(selectedObjectIndex);
        int lefttopindex = MapModifier.Instance.CaculateIndexForPos(lefttopcenter);
        int biggridindex = MapModifier.Instance.CaculatePaintedGridFromUnitIndex(lefttopindex);

        int[]   unitindexes       = MapModifier.Instance.CaculateUnitIndexesOfGrid(biggridindex);
        int     girdlefttopindex  = unitindexes[0];
        Vector3 girdlefttopcenter = MapModifier.Instance.TranselateIndexToPostion(girdlefttopindex);

        Vector3[] fourCorner = new Vector3[4];
        fourCorner[0] = new Vector3(girdlefttopcenter.x - cm.unitlength / 2f, girdlefttopcenter.y, girdlefttopcenter.z + cm.unitlength / 2f); //girdlefttopcenter ;
        fourCorner[1] = new Vector3(girdlefttopcenter.x + cm.paintedgridlength - cm.unitlength / 2f, girdlefttopcenter.y, girdlefttopcenter.z + cm.unitlength / 2f);
        fourCorner[2] = new Vector3(girdlefttopcenter.x - cm.unitlength / 2f, girdlefttopcenter.y, girdlefttopcenter.z - cm.paintedgridlength + cm.unitlength / 2f);
        fourCorner[3] = new Vector3(girdlefttopcenter.x + cm.paintedgridlength - cm.unitlength / 2f, girdlefttopcenter.y, girdlefttopcenter.z - cm.paintedgridlength + cm.unitlength / 2f);
        float min   = cm.paintedgridlength;
        int   minid = 0;

        for (int i = 0; i < 4; ++i)
        {
            float tmp = Vector3.Distance(fourCorner[i], collisionPos);
            // Debug.Log(tmp + "distance");
            if (tmp < min)
            {
                min   = tmp;
                minid = i;
            }
        }
        //Debug.Log(minid + "nearest id");
        MapAux.ShowLabel(new Vector3(lefttopcenter.x + cm.unitlength, lefttopcenter.y, lefttopcenter.z + cm.unitlength), biggridindex.ToString(), Color.black);
        if (isDrag == true)
        {
            Handles.color = Color.green;
            Handles.DrawWireDisc(start, Vector3.up, .5f);
            Handles.DrawWireDisc(end, Vector3.up, .5f);
            Handles.color = new Color(128 / 255f, 0, 128 / 255f);
            Handles.DrawLine(start, end);
            Debug.Log(start + "start end" + end);
        }
        HandleUtility.AddDefaultControl(controlID);
        switch (current.type)
        {
        case EventType.mouseDown:
            if (current.button == 0 && (!isDrag))
            {
                start = fourCorner[minid];
                // Handles.color = Color.green;
                //  Handles.DrawWireDisc(start, Vector3.up, .5f);
            }
            break;

        case EventType.mouseUp:
            if (current.button == 0 && (isDrag == false))
            {
                //  MapModifier.Instance.AddPoint(startpoint);
            }
            else if (current.button == 0 && (isDrag == true))
            {
                end = fourCorner[minid];
                //MapModifier.Instance.AddArea(startpoint, endpoint);
                isDrag = false;
            }
            break;

        case EventType.mouseDrag:
            if (current.button == 0)
            {
                end    = fourCorner[minid];
                isDrag = true;
                // Handles.DrawWireDisc(end, Vector3.up, .5f);
                // Handles.color = new Color(128 / 255f, 0, 128 / 255f);
                // Handles.DrawLine(start, end);
            }
            break;

        default:
            break;
        }
        SceneView.RepaintAll();
    }
예제 #8
0
    public override void DealWithEvent()
    {
        Event   current      = Event.current;
        int     controlID    = GUIUtility.GetControlID(FocusType.Passive);
        Vector3 collisionPos = MapModifier.Instance.CaculateCollisionPosFromGUIPoint(current.mousePosition);

        if (collisionPos.y == float.MaxValue)
        {
            return;
        }
        collisionPos = new Vector3(collisionPos.x, 0, collisionPos.z);
        Vector3 lefttopcenter = MapModifier.Instance.CaculateCellCenterByPos(collisionPos);
        int     lefttopindex  = MapModifier.Instance.CaculateIndexForPos(lefttopcenter);
        Vector3 size          = new Vector3(1, 0, 1);
        var     flag          = MapModifier.Instance.CheckContainUnreachable(lefttopindex, size);

        Handles.color = Color.green;
        Handles.DrawWireDisc(collisionPos, Vector3.up, .5f);
        //Debug.Log(current.type);
        if (isDrag == true)
        {
            MapAux.DrawRectHandles(startpoint, endpoint);
        }
        HandleUtility.AddDefaultControl(controlID);
        switch (current.type)
        {
        case EventType.mouseDown:
            if (current.button == 0 && (!isDrag))
            {
                startpoint = collisionPos;
            }
            break;

        case EventType.mouseUp:
            if (current.button == 0 && (isDrag == false))
            {
                MapModifier.Instance.AddPoint(startpoint);
            }
            else if (current.button == 0 && (isDrag == true))
            {
                endpoint = collisionPos;
                MapModifier.Instance.AddArea(startpoint, endpoint);
                isDrag = false;
            }
            break;

        case EventType.mouseDrag:
            if (current.button == 0)
            {
                endpoint = collisionPos;
                isDrag   = true;
            }
            break;

        default:
            break;
        }
        int curID = GUIUtility.hotControl;

        if (HandleRecorder.handleIDAndTarget.ContainsKey(curID))
        {
            curFocusID = curID;
        }
        if (HandleRecorder.handleIDAndTarget.ContainsKey(curFocusID))
        {
            // Handles.BeginGUI();
            // var re = SceneView.lastActiveSceneView.position;
            // GUILayout.BeginArea(new Rect(re.width / 4, re.height - 120, re.width/2, 120), EditorStyles.textArea);
            EditDetailsWindow.deleteAction = () =>
            {
                MapModifier.Instance.RemoveInfo(HandleRecorder.handleIDAndTarget[curFocusID]);
                HandleRecorder.handleIDAndTarget.Remove(curFocusID);
            };
            EditDetailsWindow.toDraw = ExposeProperties.GetProperties(HandleRecorder.handleIDAndTarget[curFocusID], out EditDetailsWindow.toDrawType);
            //ExposeProperties.Expose(m_fields);

            // GUILayout.EndArea();
            // Handles.EndGUI();
        }
        SceneView.RepaintAll();
    }