public static void OnDrawSceneGizmo(LevelCube levelNode, GizmoType gizmoType)
    {
        /*if ((gizmoType & GizmoType.Selected) != 0) Gizmos.color = Color.yellow;
         *
         * else Gizmos.color = Color.yellow * 0.5f;
         *
         * Gizmos.DrawSphere(levelNode.transform.position, .5f);*/

        //drawxw red ines to connect the nodes
        if (levelNode.nextLevel != null)
        {
            if (levelNode.nextLevel.isAnchorNode)
            {
                Gizmos.color = Color.blue;
                Gizmos.DrawLine(levelNode.transform.position, levelNode.nextLevel.transform.position);
            }

            else
            {
                Gizmos.color = Color.red;
                Gizmos.DrawLine(levelNode.transform.position, levelNode.nextLevel.transform.position);
            }
        }


        Gizmos.color = Color.green;

        if (levelNode.nextOptionalLevel != null)
        {
            Gizmos.DrawLine(levelNode.transform.position, levelNode.nextOptionalLevel.transform.position);
        }
    }
示例#2
0
    private void InsertLevel()
    {
        selectedObject = Selection.activeGameObject;
        var selectedNodeIndex = selectedObject.transform.GetSiblingIndex();

        GameObject insertedLevelObject = (GameObject)PrefabUtility.InstantiatePrefab(worldmapCube);

        insertedLevelObject.name = "Level Node " + LevelCubeRoot.childCount;
        insertedLevelObject.transform.SetParent(LevelCubeRoot, false);

        LevelCube levelCube = insertedLevelObject.GetComponent <LevelCube>();

        if (LevelCubeRoot.childCount > 1)
        {
            levelCube.previousLevel           = LevelCubeRoot.GetChild(selectedNodeIndex).gameObject.GetComponent <LevelCube>();
            levelCube.nextLevel               = levelCube.previousLevel.nextLevel;
            levelCube.previousLevel.nextLevel = levelCube;
            levelCube.nextLevel.previousLevel = levelCube;

            levelCube.transform.position = (levelCube.nextLevel.transform.position + levelCube.previousLevel.transform.position) / 2;
            levelCube.transform.forward  = levelCube.previousLevel.transform.forward;
            levelCube.transform.rotation = worldMapFace.transform.rotation;
        }

        insertedLevelObject.transform.SetSiblingIndex(selectedNodeIndex + 1);

        ResetNames(1);
    }
示例#3
0
    private void InsertAnchor()
    {
        selectedObject = Selection.activeGameObject;
        var selectedNodeIndex = selectedObject.transform.GetSiblingIndex();

        GameObject levelAnchorObject = new GameObject("Anchor Node " + anchorNodeRoot.childCount, typeof(LevelCube));

        levelAnchorObject.transform.SetParent(anchorNodeRoot, false);

        LevelCube levelAnchor = levelAnchorObject.GetComponent <LevelCube>();

        if (anchorNodeRoot.childCount >= 1)
        {
            levelAnchor.previousLevel           = LevelCubeRoot.GetChild(selectedNodeIndex).gameObject.GetComponent <LevelCube>();
            levelAnchor.nextLevel               = levelAnchor.previousLevel.nextLevel;
            levelAnchor.previousLevel.nextLevel = levelAnchor;
            levelAnchor.nextLevel.previousLevel = levelAnchor;

            levelAnchor.transform.position = (levelAnchor.nextLevel.transform.position + levelAnchor.previousLevel.transform.position) / 2;
            levelAnchor.transform.forward  = levelAnchor.previousLevel.transform.forward;
        }

        levelAnchorObject.transform.SetSiblingIndex(selectedNodeIndex + 1);

        ResetNames(3);
    }
    static void NodeAnchorCallback()
    {
        LevelCube selectedNode = Selection.activeGameObject.GetComponent <LevelCube>();

        isAnchor = !isAnchor;

        /*            if(isAnchor) selectedNode.isAnchorNode = true;
         *          else selectedNode.isAnchorNode = false;*/
    }
示例#5
0
    private void CreateWaypoint()
    {
        //create a new object and name it after the child count of the transform parent
        //after the object has been instantiated, set it as a child of the parent
        //GameObject LevelCubeObject = new GameObject("Level Node " + LevelCubeRoot.childCount, typeof(LevelCube));

        GameObject levelCubeObject = (GameObject)PrefabUtility.InstantiatePrefab(worldmapCube);

        int levelNode = ((int)currentBiome + 1) * 100 + LevelCubeRoot.childCount + 1;

        levelCubeObject.name = "Level Node " + levelNode.ToString();
        levelCubeObject.transform.SetParent(LevelCubeRoot, false);

        levelCubeObject.gameObject.layer = LayerMask.NameToLayer("LevelCubes");

        levelCubeObject.transform.position = worldMapFace.transform.GetChild(0).transform.position;

        levelCubeObject.transform.up = worldMapFace.transform.GetChild(1).transform.up;
        //levelCubeObject.transform.forward = worldMapFace.transform.GetChild(1).transform.up;

        levelCubeObject.transform.Translate(new Vector3(0, .25f, 0), Space.Self);
        //levelCubeObject.transform.position +=levelCubeObject.transform.Translate(Vector3.up, Space.Self);// levelCubeObject.transform.localPosition + new Vector3(0, .5f, 0);

        LevelCube levelCube = levelCubeObject.GetComponent <LevelCube>();

        //automatically link up the waypoints on spawn
        if (LevelCubeRoot.childCount > 1)
        {
            //as we are looking at the node placed right before the new one, we use childCount -2

            //assign the previous level as the last level in the list before this new node
            levelCube.previousLevel = LevelCubeRoot.GetChild(LevelCubeRoot.childCount - 2).gameObject.GetComponent <LevelCube>();

            //assign that node's next level as this new node
            levelCube.previousLevel.nextLevel = levelCube;

            if (createdOptionalLevel)
            {
                levelCube.prevOptionalLevel = optLevelCubeRoot.GetChild(optLevelCubeRoot.childCount - 1).gameObject.GetComponent <LevelCube>();
                LevelCube prevOptional = optLevelCubeRoot.GetChild(optLevelCubeRoot.childCount - 1).gameObject.GetComponent <LevelCube>();
                prevOptional.nextLevel = levelCube;
                createdOptionalLevel   = false;
            }

            //place the new LevelCube at the last position
            levelCube.transform.position = levelCube.previousLevel.transform.position;
            levelCube.transform.rotation = levelCube.previousLevel.transform.rotation;
            //levelCubeObject.transform.up = levelCube.previousLevel.transform.up;
            //levelCube.transform.forward = levelCube.previousLevel.transform.forward;
        }

        Selection.activeGameObject = levelCube.gameObject;
    }
示例#6
0
    // Start is called before the first frame update
    void Start()
    {
        centerPointOffset = new Vector3(0.5f, 0, 0.5f);
        int        layerMask = 1 << 9;
        RaycastHit hit;

        if (Physics.Raycast(transform.position + transform.TransformVector(centerPointOffset) + transform.TransformDirection(Vector3.up) * 0.5f, transform.TransformDirection(Vector3.down), out hit, 1.2f, layerMask))
        {
            hitPoint = hit.point;
            cube     = hit.collider.GetComponent <LevelCube>();
            grid     = cube.GetGridAtPosition(hit.point);
        }
    }
示例#7
0
文件: Switch.cs 项目: YumiiK/Regrass
    private void InitializeGrid()
    {
        int        layerMask = 1 << 9 | 1 << 10;
        RaycastHit hit;

        if (Physics.Raycast(transform.position + transform.TransformVector(centerPointOffset) + transform.TransformDirection(Vector3.up) * 0.5f, transform.TransformDirection(Vector3.down), out hit, 1.2f, layerMask))
        {
            hitPoint      = hit.point;
            affectingCube = hit.collider.GetComponent <LevelCube>();
            affectingGrid = affectingCube.GetGridAtPosition(hit.point);
            oriType       = affectingGrid.type;
        }
    }
示例#8
0
        private void CheckForNodeTouch()
        {
            if (Physics.Raycast(Camera.main.ScreenPointToRay(LevelEditor.GetUserPlatform()), out hit, Mathf.Infinity, cubesMask))
            {
                LevelCube levelCube = hit.collider.gameObject.GetComponent <LevelCube>();

                if (levelCube != null)
                {
                    foreach (LevelCube cube in worldMapLevels)
                    {
                        cube.GetComponent <_ScriptMatFaceCube>().IsNotSelectedAnymore();
                    }


                    levelCube.gameObject.GetComponent <_ScriptMatFaceCube>().isSelected = true;
                    LevelsManager.instance.SelectLevel(levelCube.kubicode);
                }
            }
        }
示例#9
0
    private void CreateBranchingPath()
    {
        createdOptionalLevel = true;
        GameObject optLevelCubeObject = (GameObject)PrefabUtility.InstantiatePrefab(worldmapCube);

        optLevelCubeObject.name = "Optional Level Node " + optLevelCubeRoot.childCount;
        optLevelCubeObject.transform.SetParent(optLevelCubeRoot, false);

        LevelCube optLevelCube = optLevelCubeObject.GetComponent <LevelCube>();

        if (optLevelCubeRoot.childCount >= 1)
        {
            //get the last level node of the regular level Node List (so use -1 instead of -2)
            optLevelCube.previousLevel = LevelCubeRoot.GetChild(LevelCubeRoot.childCount - 1).gameObject.GetComponent <LevelCube>();
            //set the current node as the next optional level
            optLevelCube.previousLevel.nextOptionalLevel = optLevelCube;

            optLevelCube.transform.position = optLevelCube.previousLevel.transform.position;
            optLevelCube.transform.forward  = optLevelCube.previousLevel.transform.forward;
            optLevelCube.transform.rotation = worldMapFace.transform.rotation;
        }
    }
    static void OnSceneGUI(SceneView sceneView)
    {
        if (Event.current.button == 1 && Event.current.type == EventType.MouseDown)
        {
            if (Selection.activeGameObject != null)
            {
                selectedNode = Selection.activeGameObject.GetComponent <LevelCube>();

                if (selectedNode != null)
                {
                    isOptional = selectedNode.isOptionalLevel;
                    isAnchor   = selectedNode.isAnchorNode;

                    GenericMenu myMenu = new GenericMenu();
                    myMenu.AddDisabledItem(new GUIContent("Set Node Type"));
                    myMenu.AddItem(new GUIContent("Level is Optional"), isOptional, NodeCallback);
                    myMenu.AddItem(new GUIContent("is Path Anchor"), isAnchor, NodeAnchorCallback);

                    myMenu.ShowAsContext();
                }
            }
        }
    }
示例#11
0
    private void DeleteNode()
    {
        LevelCube LevelCubeToDestroy = Selection.activeGameObject.GetComponent <LevelCube>();

        if (LevelCubeToDestroy.nextLevel != null)
        {
            LevelCubeToDestroy.nextLevel.previousLevel = LevelCubeToDestroy.previousLevel;
        }
        if (LevelCubeToDestroy.previousLevel != null)
        {
            LevelCubeToDestroy.previousLevel.nextLevel = LevelCubeToDestroy.nextLevel;
        }

        if (LevelCubeToDestroy.nextOptionalLevel != null)
        {
            LevelCubeToDestroy.previousLevel.nextOptionalLevel = LevelCubeToDestroy.nextOptionalLevel;
        }
        if (LevelCubeToDestroy.prevOptionalLevel != null)
        {
            LevelCubeToDestroy.nextLevel.prevOptionalLevel = LevelCubeToDestroy.prevOptionalLevel;
        }

        DestroyImmediate(LevelCubeToDestroy.gameObject);

        if (LevelCubeToDestroy.isOptionalLevel)
        {
            ResetNames(2);
        }
        else if (LevelCubeToDestroy.isAnchorNode)
        {
            ResetNames(3);
        }
        else
        {
            ResetNames(1);
        }
    }
示例#12
0
    // Update is called once per frame
    void Update()
    {
        //fs = GameObject.FindGameObjectsWithTag("FrontSight");
        //fs[0].SetActive(true);
        //fs[1].SetActive(false);
        //输入判断
        switch (mouseButtonDown)
        {
        case 0:
        {
            if (Input.GetMouseButtonDown(0))
            {
                mouseButtonDown = 1;
            }

            if (Input.GetMouseButtonDown(1))
            {
                if (mouseButtonDown == 0)
                {
                    mouseButtonDown = 2;
                }
                else
                {
                    mouseButtonDown = 0;
                }
            }

            if (mouseButtonDown == 0)
            {
                if (Input.GetAxis("Mouse ScrollWheel") < 0)         //鼠标后滚
                {
                    //Done:Change Water color
                    //如果此时已经是最后一个颜色,那么就从第一个开始重新后滚(形成循环)
                    if (waterColor == WaterColor.BLUE)
                    {
                        waterColor = WaterColor.RED;
                    }
                    else
                    {
                        waterColor = waterColor + 1;
                    }
                    //Debug.Log("Hougun--");
                    //Debug.Log((int)waterColor);
                }
                else if (Input.GetAxis("Mouse ScrollWheel") > 0)         //鼠标前滚
                {
                    //Done:Change Water color
                    if (waterColor == WaterColor.RED)
                    {
                        waterColor = WaterColor.BLUE;
                    }
                    else
                    {
                        waterColor = waterColor - 1;
                    }
                    //Debug.Log("Qiangun--");
                    //Debug.Log((int)waterColor);
                }

                //waterParticle = particles[(int)waterColor - 1];
            }
            break;
        }

        case 1:
        {
            if (Input.GetMouseButtonUp(0))
            {
                mouseButtonDown = 0;
                //waterParticle.Stop();
                //TODO:修改UI
                fs_big.SetActive(true);
                fs_small.SetActive(false);
            }
            else
            {
                if (selectingGrid != null)
                {
                    selectingGrid.SprayWater(waterColor);
                    selectingCube.SprayWaterAtPosition(targetPoint, waterColor);
                }
                //WaterAnimation();

                //TODO:修改UI
                fs_big.SetActive(false);
                fs_small.SetActive(true);
            }
            break;
        }

        case 2:
        {
            if (Input.GetMouseButtonUp(1))
            {
                mouseButtonDown = 0;
            }
            else
            {
                if (selectingGrid != null)
                {
                    selectingGrid.ClearGrid();
                }
            }
            break;
        }
        }

        //Raycast
        int        layerMask = 1 << 9 | 1 << 10;
        RaycastHit hit;

        if (Physics.Raycast(transform.position, transform.TransformDirection(Vector3.forward), out hit, waterGunRange, layerMask))
        {
            targetPoint   = hit.point;
            selectingCube = hit.collider.GetComponent <LevelCube>();
            if (selectingCube != null)
            {
                selectingGrid = selectingCube.GetGridAtPosition(hit.point);
            }
            else
            {
                selectingGrid = null;
            }
            //selectingGrid = hit.collider.GetComponent<GridSplitter>().GetGridAtPosition(hit.point);
            //Debug.DrawRay(transform.position, transform.TransformDirection(Vector3.forward) * hit.distance, Color.yellow);
        }
        else
        {
            targetPoint   = transform.position + transform.TransformDirection(Vector3.forward) * waterGunRange; //这里可能有问题
            selectingGrid = null;
            //Debug.DrawRay(transform.position, transform.TransformDirection(Vector3.forward) * 1000, Color.white);
        }

        //高亮
        HighlightGrid();

        //if (selectingGrid != null)
        //{
        //    debugText.text = $"Position:{selectingGrid.position}   State:{selectingGrid.state}   Luminance:{selectingGrid.luminance}   Type:{selectingGrid.type}";
        //    for(int i = 0;i < selectingGrid.grassStates.Length; i++)
        //    {
        //        debugText.text += $"\ngrassState[{i}] = {selectingGrid.grassStates[i]}";
        //    }
        //    //LevelGrid grid = selectingGrid.GetNearGrid(NearGridDirection.LEFT);
        //    //if (grid != null)
        //    //{
        //    //    debugText.text += $"\nLEFT:{grid.position} - {grid.groundColor}";
        //    //}
        //    //else
        //    //{
        //    //    debugText.text += "\nLEFT:NULL";
        //    //}
        //    //grid = selectingGrid.GetNearGrid(NearGridDirection.RIGHT);
        //    //if (grid != null)
        //    //{
        //    //    debugText.text += $"\nRIGHT:{grid.position} - {grid.groundColor}";
        //    //}
        //    //else
        //    //{
        //    //    debugText.text += "\nRIGHT:NULL";
        //    //}
        //    //grid = selectingGrid.GetNearGrid(NearGridDirection.FORWARD);
        //    //if (grid != null)
        //    //{
        //    //    debugText.text += $"\nFORWARD:{grid.position} - {grid.groundColor}";
        //    //}
        //    //else
        //    //{
        //    //    debugText.text += "\nFORWARD:NULL";
        //    //}
        //    //grid = selectingGrid.GetNearGrid(NearGridDirection.BACK);
        //    //if (grid != null)
        //    //{
        //    //    debugText.text += $"\nBACK:{grid.position} - {grid.groundColor}";
        //    //}
        //    //else
        //    //{
        //    //    debugText.text += "\nBACK:NULL";
        //    //}

        //}
        //else
        //{
        //    debugText.text = "NULL";
        //}
    }