Ejemplo n.º 1
0
        //check if creating a new submesh is possible
        private bool CheckSubMesh()
        {
            NavMeshManagerEditor.GetSceneView().Focus();

            //get count of all submeshes
            int subPointsCount = script.subPoints.Count;

            if (subPointsCount > 0 && script.subPoints[subPointsCount - 1].list.Count <= 2)
            {
                NavMeshManagerEditor.ShowNotification("Resuming current submesh.");
                return(false);
            }

            return(true);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Creates a portal container gameobject with portals as its children.
        /// </summary>
        public void CreateNewPortal()
        {
            //get the current unix timestamp for a unique naming scheme
            var    epochStart = new System.DateTime(1970, 1, 1, 0, 0, 0, System.DateTimeKind.Utc);
            string timestamp  = (System.DateTime.UtcNow - epochStart).TotalSeconds.ToString("F0");

            //create portal container with unique name
            GameObject portalGO = new GameObject();

            portalGO.transform.parent = script.transform;
            portalGO.name             = "Portal " + timestamp;
            portalGO.AddComponent <PortalObject>();

            //try to get a position in the center of our scene view,
            //one near position directly at the camera and a position 10 units far away
            Camera  sceneCam = NavMeshManagerEditor.GetSceneView().camera;
            Vector3 camNear  = sceneCam.ViewportToWorldPoint(new Vector3(0.5f, 0.5f, 0f));
            Vector3 camFar   = sceneCam.ViewportToWorldPoint(new Vector3(0.5f, 0.5f, 10f));
            //calculate direction from near to far position
            Vector3 dir = (camFar - camNear).normalized;

            //set the portal container to the far position as default
            portalGO.transform.position = camFar;

            //raycast in the center of the scene view,
            //if the ray hits something the portal container gets positioned there
            RaycastHit hit;

            if (Physics.Raycast(camNear, dir, out hit))
            {
                portalGO.transform.position = hit.point;
            }

            //create child objects/portals
            for (int i = 0; i < 2; i++)
            {
                GameObject child = new GameObject("" + i);
                child.transform.parent = portalGO.transform;
            }

            //reposition them around the portal container
            portalGO.transform.GetChild(0).position = portalGO.transform.position + Vector3.left;
            portalGO.transform.GetChild(1).position = portalGO.transform.position + Vector3.right;

            Undo.RegisterCreatedObjectUndo(portalGO, "Created Portal");
            Selection.activeGameObject = portalGO;
        }
Ejemplo n.º 3
0
        private bool CheckCombine(NavMeshObject script)
        {
            //get count of all submeshes
            int subPointsCount = script.subPoints.Count;

            if (subPointsCount > 0)
            {
                //remove submesh without references
                if (script.subPoints[subPointsCount - 1].list.Count == 0)
                {
                    script.subPoints.RemoveAt(subPointsCount - 1);
                }
                else if (script.subPoints[subPointsCount - 1].list.Count <= 2)
                {
                    NavMeshManagerEditor.ShowNotification("Can't combine submeshes.\nYou haven't placed enough points.");
                    return(false);
                }
            }

            return(true);
        }
Ejemplo n.º 4
0
        //check if a combine of submeshes is possible
        private void CheckCombine()
        {
            NavMeshManagerEditor.GetSceneView().Focus();

            //get count of all submeshes
            int subPointsCount = script.subPoints.Count;

            if (script.subPoints.Count == 0)
            {
                return;
            }
            NavMeshObject.SubPoints lastPoints = script.subPoints[subPointsCount - 1];

            if (lastPoints.list.Count <= 2)
            {
                selected.Clear();
                for (int i = 0; i < lastPoints.list.Count; i++)
                {
                    selected.Add(lastPoints.list[i]);
                }

                DeleteSelected();
            }
        }