Пример #1
0
        /// <summary>
        /// Use this to create nodes via coding while in editor mode. Make sure opt_bAllowRoadUpdates is set to false in RS.GSDRS.opt_bAllowRoadUpdates.
        /// </summary>
        /// <param name="RS">The road system to create nodes on.</param>
        /// <param name="NodeLocation">The location of the newly created node.</param>
        /// <returns></returns>
        public static GSDSplineN CreateNode_Programmatically(GSDRoad tRoad, Vector3 NodeLocation)
        {
            int        SplineChildCount = tRoad.GSDSpline.transform.childCount;
            GameObject tNodeObj         = new GameObject("Node" + (SplineChildCount + 1).ToString());
            GSDSplineN tNode            = tNodeObj.AddComponent <GSDSplineN>(); //Add the node component.

            //Set node location:
            if (NodeLocation.y < 0.03f)
            {
                NodeLocation.y = 0.03f;
            }                                                           //Make sure it doesn't try to create a node below 0 height.
            tNodeObj.transform.position = NodeLocation;

            //Set the node's parent:
            tNodeObj.transform.parent = tRoad.GSDSplineObj.transform;

            //Set the idOnSpline:
            tNode.idOnSpline = (SplineChildCount + 1);
            tNode.GSDSpline  = tRoad.GSDSpline;

            //Make sure opt_bAllowRoadUpdates is set to false in RS.GSDRS.opt_bAllowRoadUpdates
            tRoad.UpdateRoad();

            return(tNode);
        }
    public static void UpdateAllRoads()
    {
        GSDRoad[] tRoadObjs = (GSDRoad[])GameObject.FindObjectsOfType(typeof(GSDRoad));

        int RoadCount = tRoadObjs.Length;

        GSDRoad tRoad = null;

        GSDSplineC[] tPiggys = null;
        if (RoadCount > 1)
        {
            tPiggys = new GSDSplineC[RoadCount - 1];
        }

        for (int h = 0; h < RoadCount; h++)
        {
            tRoad = tRoadObjs[h];
            if (h > 0)
            {
                tPiggys[h - 1] = tRoad.GSDSpline;
            }
        }

        tRoad = tRoadObjs[0];
        if (tPiggys != null && tPiggys.Length > 0)
        {
            tRoad.PiggyBacks = tPiggys;
        }
        tRoad.UpdateRoad();
    }
    public static void UpdateAllRoads()
    {
        GSDRoad[] allRoadObjects = (GSDRoad[])GameObject.FindObjectsOfType(typeof(GSDRoad));

        int roadCount = allRoadObjects.Length;

        GSDRoad singleRoad = null;

        GSDSplineC[] tPiggys = null;
        if (roadCount > 1)
        {
            tPiggys = new GSDSplineC[roadCount - 1];
        }

        for (int count = 0; count < roadCount; count++)
        {
            singleRoad = allRoadObjects[count];
            if (count > 0)
            {
                tPiggys[count - 1] = singleRoad.GSDSpline;
            }
        }

        singleRoad = allRoadObjects[0];
        if (tPiggys != null && tPiggys.Length > 0)
        {
            singleRoad.PiggyBacks = tPiggys;
        }
        singleRoad.UpdateRoad();
    }
Пример #4
0
    public void UpdateAllRoads()
    {
        GSDRoad[] tRoadObjs = GetComponentsInChildren <GSDRoad>();
        //		int i=0;

        int RoadCount = tRoadObjs.Length;

        GSDRoad tRoad = null;

        GSDSplineC[] tPiggys = null;
        if (RoadCount > 1)
        {
            tPiggys = new GSDSplineC[RoadCount];
            for (int h = 0; h < RoadCount; h++)
            {
                tRoad      = tRoadObjs[h];
                tPiggys[h] = tRoad.GSDSpline;
            }
        }

        tRoad = tRoadObjs[0];
        if (tPiggys != null && tPiggys.Length > 0)
        {
            tRoad.PiggyBacks = tPiggys;
        }
        tRoad.UpdateRoad();
    }
Пример #5
0
		public static GSDSplineN CreateNode(GSDRoad RS, bool bSpecialEndNode = false, Vector3 vSpecialLoc = default(Vector3), bool bInterNode = false){
			Object[] tWorldNodeCount = GameObject.FindObjectsOfType(typeof(GSDSplineN));
			GameObject tNodeObj = new GameObject("Node" + tWorldNodeCount.Length.ToString());
			if(!bInterNode){
				UnityEditor.Undo.RegisterCreatedObjectUndo(tNodeObj, "Created node");
			}
			GSDSplineN tNode = tNodeObj.AddComponent<GSDSplineN>();

			if(bSpecialEndNode){
				tNode.bSpecialEndNode = true;
				tNodeObj.transform.position = vSpecialLoc;
			}else{
				tNodeObj.transform.position = RS.Editor_MousePos;
				//This helps prevent double clicks:
				int mCount = RS.GSDSpline.GetNodeCount();
				for(int i=0;i<mCount;i++){
					if(Vector3.Distance(RS.Editor_MousePos,RS.GSDSpline.mNodes[i].pos) < 5f){
						Object.DestroyImmediate(tNodeObj);
						return null;
					}
				}
				//End double click prevention
			}
			Vector3 xVect = tNodeObj.transform.position;
			if(xVect.y < 0.03f){ xVect.y = 0.03f; }
			tNodeObj.transform.position = xVect;

			tNodeObj.transform.parent = RS.GSDSplineObj.transform;
			tNode.idOnSpline = RS.GSDSpline.GetNodeCount()+1;
			tNode.GSDSpline = RS.GSDSpline;
			
			//Enforce max road grade:
			if(RS.opt_bMaxGradeEnabled && !bSpecialEndNode){
				tNode.EnsureGradeValidity(-1,true);
			}
			
			if(!bInterNode && !bSpecialEndNode){
				RS.UpdateRoad();
			}
			return tNode;
		}
Пример #6
0
        /// <summary>
        /// Use this to create nodes via coding while in editor mode. Make sure opt_bAllowRoadUpdates is set to false in RS.GSDRS.opt_bAllowRoadUpdates.
        /// </summary>
        /// <param name="RS">The road system to create nodes on.</param>
        /// <param name="NodeLocation">The location of the newly created node.</param>
        /// <returns></returns>
        public static GSDSplineN CreateNode_Programmatically(GSDRoad tRoad, Vector3 NodeLocation) {
            int SplineChildCount = tRoad.GSDSpline.transform.childCount;
			GameObject tNodeObj = new GameObject("Node" + (SplineChildCount+1).ToString());
			GSDSplineN tNode = tNodeObj.AddComponent<GSDSplineN>(); //Add the node component.

            //Set node location:
            if (NodeLocation.y < 0.03f) { NodeLocation.y = 0.03f; }     //Make sure it doesn't try to create a node below 0 height.
            tNodeObj.transform.position = NodeLocation;

            //Set the node's parent:
            tNodeObj.transform.parent = tRoad.GSDSplineObj.transform;     

            //Set the idOnSpline:
            tNode.idOnSpline = (SplineChildCount + 1);
            tNode.GSDSpline = tRoad.GSDSpline;

            //Make sure opt_bAllowRoadUpdates is set to false in RS.GSDRS.opt_bAllowRoadUpdates
            tRoad.UpdateRoad();

            return tNode;
		}
Пример #7
0
        /// <summary>
        /// Use this to insert nodes via coding while in editor mode. Make sure opt_bAllowRoadUpdates is set to false in RS.GSDRS.opt_bAllowRoadUpdates.
        /// </summary>
        /// <param name="RS">The road system to insert nodes in.</param>
        /// <param name="NodeLocation">The location of the newly inserted node.</param>
        /// <returns></returns>
		public static GSDSplineN InsertNode_Programmatically(GSDRoad RS, Vector3 NodeLocation){
			GameObject tNodeObj;
			Object[] tWorldNodeCount = GameObject.FindObjectsOfType(typeof(GSDSplineN));
            tNodeObj = new GameObject("Node" + tWorldNodeCount.Length.ToString());	
			
            //Set node location:
            if (NodeLocation.y < 0.03f) { NodeLocation.y = 0.03f; }     //Make sure it doesn't try to create a node below 0 height.
            tNodeObj.transform.position = NodeLocation;

            //Set the node's parent:
            tNodeObj.transform.parent = RS.GSDSplineObj.transform;    
			
			int cCount = RS.GSDSpline.mNodes.Count;

            //Get the closet param on spline:
			float tParam = RS.GSDSpline.GetClosestParam(NodeLocation, false, true);
			
			bool bEndInsert = false;
			bool bZeroInsert = false;
			int iStart = 0;
			if(GSDRootUtil.IsApproximately(tParam,0f,0.0001f)){
				bZeroInsert = true;
				iStart = 0;
            } else if (GSDRootUtil.IsApproximately(tParam, 1f, 0.0001f)) {
                //Inserted at end, switch to create node instead:
                Object.DestroyImmediate(tNodeObj);
                return CreateNode_Programmatically(RS, NodeLocation);
			}
			
            //Figure out where to insert the node:
			for(int i=0;i<cCount;i++){
				GSDSplineN xNode = RS.GSDSpline.mNodes[i];
				if(!bZeroInsert && !bEndInsert){
					if(tParam > xNode.tTime){
						iStart = xNode.idOnSpline+1;
					}
				}
			}
			for(int i=iStart;i<cCount;i++){
				RS.GSDSpline.mNodes[i].idOnSpline+=1;
			}
			
			GSDSplineN tNode = tNodeObj.AddComponent<GSDSplineN>();
			tNode.GSDSpline = RS.GSDSpline;
			tNode.idOnSpline = iStart;
            tNode.pos = NodeLocation;
			RS.GSDSpline.mNodes.Insert(iStart,tNode);

            //Make sure opt_bAllowRoadUpdates is set to false in RS.GSDRS.opt_bAllowRoadUpdates
            RS.UpdateRoad();
			
			return tNode;
		}
Пример #8
0
		//Insert
		//Detect closest node (if end node, auto select other node)
		//Determine which node is closest (up or down) on spline
		//Place node, adjust all id on splines
		//Setup spline
		public static GSDSplineN InsertNode(GSDRoad RS, bool bForcedLoc = false, Vector3 ForcedLoc = default(Vector3), bool bIsPreNode = false, int InsertIndex = -1, bool bSpecialEndNode = false, bool bInterNode = false){
			GameObject tNodeObj;
			Object[] tWorldNodeCount = GameObject.FindObjectsOfType(typeof(GSDSplineN));
			if(!bForcedLoc){
				tNodeObj = new GameObject("Node" + tWorldNodeCount.Length.ToString());	
			}else if(bForcedLoc && !bSpecialEndNode){
				tNodeObj = new GameObject("Node" + tWorldNodeCount.Length.ToString() + "Ignore");
			}else{
				tNodeObj = new GameObject("Node" + tWorldNodeCount.Length.ToString());	
			}
			if(!bInterNode){
				UnityEditor.Undo.RegisterCreatedObjectUndo(tNodeObj, "Inserted node");
			}
			
			if(!bForcedLoc){
				tNodeObj.transform.position = RS.Editor_MousePos;
				
				//This helps prevent double clicks:
				int mCount = RS.GSDSpline.GetNodeCount();
				for(int i=0;i<mCount;i++){
					if(Vector3.Distance(RS.Editor_MousePos,RS.GSDSpline.mNodes[i].pos) < 15f){
						Object.DestroyImmediate(tNodeObj);
						return null;
					}
				}
				//End double click prevention
			}else{
				tNodeObj.transform.position = ForcedLoc;
			}
			Vector3 xVect = tNodeObj.transform.position;
			if(xVect.y < 0.03f){ xVect.y = 0.03f; }
			tNodeObj.transform.position = xVect;
			tNodeObj.transform.parent = RS.GSDSplineObj.transform;
			
			int cCount = RS.GSDSpline.mNodes.Count;
//			float mDistance = 50000f;
//			float tDistance = 0f;
			
			float tParam; 
			if(!bForcedLoc){
				tParam = RS.GSDSpline.GetClosestParam(RS.Editor_MousePos,false,true);
			}else{
				tParam = RS.GSDSpline.GetClosestParam(ForcedLoc,false,true);
			}
			bool bEndInsert = false;
			bool bZeroInsert = false;
			int iStart = 0;
            if (GSDRootUtil.IsApproximately(tParam, 0f, 0.0001f)) {
				bZeroInsert = true;
				iStart = 0;
            } else if (GSDRootUtil.IsApproximately(tParam, 1f, 0.0001f)) {
				bEndInsert = true;
			}
			
			if(bForcedLoc){
				iStart = InsertIndex;
			}else{
				for(int i=0;i<cCount;i++){
					GSDSplineN xNode = RS.GSDSpline.mNodes[i];
					if(!bZeroInsert && !bEndInsert){
						if(tParam > xNode.tTime){
							iStart = xNode.idOnSpline+1;
						}
					}
				}
			}
	
			if(bEndInsert){
				iStart = RS.GSDSpline.mNodes.Count;
			}else{
				for(int i=iStart;i<cCount;i++){
					RS.GSDSpline.mNodes[i].idOnSpline+=1;
				}
			}
			
			GSDSplineN tNode = tNodeObj.AddComponent<GSDSplineN>();
			if(bForcedLoc && !bSpecialEndNode){
				tNode.bIsBridge = true;
				tNode.bIgnore = true;
//				tNode.bIsBridge_PreNode = bIsPreNode;
//				tNode.bIsBridge_PostNode = !bIsPreNode;	
			}
			tNode.GSDSpline = RS.GSDSpline;
			tNode.idOnSpline = iStart;
			tNode.bSpecialEndNode = bSpecialEndNode;
			if(!bForcedLoc){
				tNode.pos = RS.Editor_MousePos;
			}else{
				tNode.pos = ForcedLoc;
			}
			
			RS.GSDSpline.mNodes.Insert(iStart,tNode);
	
			//Enforce maximum road grade:
			if(!bForcedLoc && !bSpecialEndNode && RS.opt_bMaxGradeEnabled){
				tNode.EnsureGradeValidity(iStart);
			}

			if(!bInterNode && !bSpecialEndNode){
				if(!bForcedLoc){
					RS.UpdateRoad();
				}
			}
			
			return tNode;
		}
Пример #9
0
        /// <summary>
        /// Use this to insert nodes via coding while in editor mode. Make sure opt_bAllowRoadUpdates is set to false in RS.GSDRS.opt_bAllowRoadUpdates.
        /// </summary>
        /// <param name="RS">The road system to insert nodes in.</param>
        /// <param name="NodeLocation">The location of the newly inserted node.</param>
        /// <returns></returns>
        public static GSDSplineN InsertNode_Programmatically(GSDRoad RS, Vector3 NodeLocation)
        {
            GameObject tNodeObj;

            Object[] tWorldNodeCount = GameObject.FindObjectsOfType(typeof(GSDSplineN));
            tNodeObj = new GameObject("Node" + tWorldNodeCount.Length.ToString());

            //Set node location:
            if (NodeLocation.y < 0.03f)
            {
                NodeLocation.y = 0.03f;
            }                                                           //Make sure it doesn't try to create a node below 0 height.
            tNodeObj.transform.position = NodeLocation;

            //Set the node's parent:
            tNodeObj.transform.parent = RS.GSDSplineObj.transform;

            int cCount = RS.GSDSpline.mNodes.Count;

            //Get the closet param on spline:
            float tParam = RS.GSDSpline.GetClosestParam(NodeLocation, false, true);

            bool bEndInsert  = false;
            bool bZeroInsert = false;
            int  iStart      = 0;

            if (GSDRootUtil.IsApproximately(tParam, 0f, 0.0001f))
            {
                bZeroInsert = true;
                iStart      = 0;
            }
            else if (GSDRootUtil.IsApproximately(tParam, 1f, 0.0001f))
            {
                //Inserted at end, switch to create node instead:
                Object.DestroyImmediate(tNodeObj);
                return(CreateNode_Programmatically(RS, NodeLocation));
            }

            //Figure out where to insert the node:
            for (int i = 0; i < cCount; i++)
            {
                GSDSplineN xNode = RS.GSDSpline.mNodes[i];
                if (!bZeroInsert && !bEndInsert)
                {
                    if (tParam > xNode.tTime)
                    {
                        iStart = xNode.idOnSpline + 1;
                    }
                }
            }
            for (int i = iStart; i < cCount; i++)
            {
                RS.GSDSpline.mNodes[i].idOnSpline += 1;
            }

            GSDSplineN tNode = tNodeObj.AddComponent <GSDSplineN>();

            tNode.GSDSpline  = RS.GSDSpline;
            tNode.idOnSpline = iStart;
            tNode.pos        = NodeLocation;
            RS.GSDSpline.mNodes.Insert(iStart, tNode);

            //Make sure opt_bAllowRoadUpdates is set to false in RS.GSDRS.opt_bAllowRoadUpdates
            RS.UpdateRoad();

            return(tNode);
        }