示例#1
0
    // Update is called once per frame
    void Update()
    {
        if (Input.GetMouseButtonDown(0))
        {
            Vector3 pos = Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, 40));
            if (publicvar.number < 1)
            {
                GameObject haha = spline.AddSplineNode();

                haha.transform.position = new Vector3(pos.x, pos.y, pos.z);

                //********************
                haha.AddComponent <MeshFilter>().mesh = new Mesh();

                GameObject temp = GameObject.CreatePrimitive(PrimitiveType.Sphere);
                haha.GetComponent <MeshFilter>().sharedMesh = temp.GetComponent <MeshFilter>().sharedMesh;
                Destroy(temp);
                //*****************
                haha.AddComponent <MeshRenderer>();
                haha.AddComponent <SphereCollider>();
                haha.GetComponent <Renderer>().material.color = Color.white;
                //haha.AddComponent<moveA>().enabled=false;

                haha.name = ("dot" + publicvar.number);
                //haha.AddComponent<SplineNode>();
                //haha.AddComponent<NodeCreator>();

                splineMesh.segmentCount += 3;
                publicvar.number++;
            }
            else
            {
                GameObject haha = spline.AddSplineNode();
                haha.transform.position = new Vector3(pos.x, pos.y, pos.z);

                haha.AddComponent <MeshFilter>().mesh = new Mesh();
                //*****************
                GameObject temp = GameObject.CreatePrimitive(PrimitiveType.Sphere);
                haha.GetComponent <MeshFilter>().sharedMesh = temp.GetComponent <MeshFilter>().sharedMesh;
                Destroy(temp);
                //*****************
                haha.AddComponent <SphereCollider>();
                haha.AddComponent <MeshRenderer>();
                haha.GetComponent <Renderer>().material.color = Color.white;
                //haha.AddComponent<moveA>().enabled = false;

                haha.name = ("dot" + publicvar.number);
                //haha.AddComponent<SplineNode>();
                splineMesh.segmentCount += 3;
                publicvar.number++;
            }
        }



        print(publicvar.number);
    }
        public override void OnInitialized()
        {
            AlbertsGuards = this;

            Transform splineNodeTransform = gameObject.CreateChild("GuardPath");

            GuardPath                   = splineNodeTransform.gameObject.AddComponent <Spline> ();
            GuardPath.updateMode        = Spline.UpdateMode.DontUpdate;
            GuardPath.autoClose         = false;
            GuardPath.normalMode        = Spline.NormalMode.UseGlobalSplineNormal;
            GuardPath.interpolationMode = Spline.InterpolationMode.Hermite;

            for (int i = 0; i < State.GuardPathNodes.Count; i++)
            {
                GameObject sn = GuardPath.AddSplineNode();
                sn.transform.parent        = splineNodeTransform;
                sn.transform.localPosition = State.GuardPathNodes [i];
            }

            GuardPath.UpdateSpline();

            //latch on to the visitable for the parent location
            worlditem.OnActive  += OnActive;
            worlditem.OnVisible += OnInvisible;
        }
示例#3
0
    private void ConvertJson(string info, int count)
    {
        GameObject baseObj = new GameObject();

        baseObj.name = "BaseSplines";
        Dictionary <string, object> table = MiniJSON.Json.Deserialize(info) as Dictionary <string, object>;
        //Object pathPref = Resources.Load("Prefabs/PathExample", typeof(GameObject));
        GameObject pathPref = EditorGUIUtility.Load("PathExample.prefab") as GameObject;

        foreach (string key in table.Keys)
        {
            GameObject pathObj = Instantiate(pathPref) as GameObject;
            pathObj.name             = key;
            pathObj.transform.parent = baseObj.transform;
            Spline        spline     = pathObj.GetComponent <Spline>();
            SplineMesh    splineMesh = pathObj.GetComponent <SplineMesh>();
            List <object> singlePath = table[key] as List <object>;
            foreach (object point in singlePath)
            {
                Dictionary <string, object> pathPoint = point as Dictionary <string, object>;
                float      x             = float.Parse(pathPoint["x"].ToString());
                float      y             = float.Parse(pathPoint["y"].ToString());
                GameObject newSplineNode = spline.AddSplineNode();
                newSplineNode.transform.position = new Vector3(x, y, 0);
                newSplineNode.transform.parent   = pathObj.transform;
                splineMesh.segmentCount         += 3;
            }
        }
    }
示例#4
0
        public void BuildSpline()
        {
            if (spline != null)
            {
                foreach (SplineNode existingNode in spline.splineNodesArray)
                {
                    GameObject.DestroyImmediate(existingNode.gameObject);
                }
                spline.splineNodesArray.Clear();
                GameObject.DestroyImmediate(spline.gameObject);
            }

            spline = gameObject.FindOrCreateChild("Spline").gameObject.GetOrAdd <Spline> ();
            //put the spline at the center of our path bounds so it's easy to select
            spline.transform.position = State.PathBounds.center;

            if (spline.splineNodesArray.Count != State.Templates.Count)
            {
                foreach (PathMarkerInstanceTemplate template in State.Templates)
                {
                    GameObject splineNode = spline.AddSplineNode();
                    splineNode.transform.parent   = spline.transform;
                    splineNode.transform.position = template.Position;
                    PathMarkerTemplateEditor pmte = splineNode.gameObject.AddComponent <PathMarkerTemplateEditor> ();
                    pmte.Template = template;
                }
            }
        }
示例#5
0
    // Update is called once per frame
    void Update()
    {
        Move( );

        //Insert a new node if space is pressed
        if (Input.GetKeyDown(KeyCode.Space))
        {
            publicvar.number++;
            //Create a new spline node at the spline's end and store the created gameObject in a variable.
            GameObject newSplineNode = spline.AddSplineNode( );

            //Set the new node's position to the current position of the character.
            newSplineNode.transform.position = this.transform.position;

            //Increase the segment count of the spline mesh, so that it doesn't look edgy when
            //the spline gets very long
            splineMesh.segmentCount += 3;
        }

        //Delete the first node when X is pressed
        if (Input.GetKeyDown(KeyCode.X))
        {
            //Get the array of nodes
            SplineNode[] splineNodes = spline.SplineNodes;

            //If there are no spline nodes left, return
            if (splineNodes.Length < 1)
            {
                Destroy(GameObject.Find("dot0"));
                spline.RemoveSplineNode(GameObject.Find("dot0"));
                publicvar.number = 0;

                return;
            }

            //Get the spline's first node

            //нье╗к║
            //SplineNode firstNode = splineNodes[0];
            SplineNode firstNode = splineNodes[publicvar.number - 1];


            //Remove it from the spline
            //spline.RemoveSplineNode( firstNode );
            spline.RemoveSplineNode(firstNode);

            splineMesh.segmentCount -= 3;

            Destroy(GameObject.Find("dot" + (publicvar.number - 1)));
            publicvar.number--;
        }
    }
    private static void SetupChildren(Spline spline)
    {
        for (int i = 0; i < 4; i++)
        {
            GameObject newNode = spline.AddSplineNode( );

            newNode.name                    = GetNodeName(i);
            newNode.transform.parent        = spline.transform;
            newNode.transform.localPosition = -Vector3.forward * 1.5f + Vector3.forward * i + (Vector3.right * ((i % 3 == 0) ? 0 : ((i % 3) - 1.5f)));
            newNode.transform.localRotation = Quaternion.identity;
            newNode.transform.localScale    = Vector3.one;
        }
    }
示例#7
0
	private static void SetupChildren( Spline spline )
	{
		for( int i = 0; i < 4; i++ )
		{
			GameObject newNode = spline.AddSplineNode( );
			
			newNode.name = GetNodeName( i );
			newNode.transform.parent = spline.transform;
			newNode.transform.localPosition = -Vector3.forward * 1.5f + Vector3.forward * i + ( Vector3.right * ((i%3==0) ? 0 : ((i%3) - 1.5f )) );
			newNode.transform.localRotation = Quaternion.identity;
			newNode.transform.localScale = Vector3.one;
		}
	}
示例#8
0
 protected IEnumerator RefreshSplineNodes()
 {
     for (int i = 0; i < Props.Nodes.Count; i++)
     {
         SVector3   nodePosition = Props.Nodes [i];
         GameObject node         = MasterSpline.AddSplineNode();
         node.transform.parent        = tr;
         node.transform.localPosition = nodePosition;
         double waitUntil = WorldClock.RealTime + 0.01f;
         while (WorldClock.RealTime < waitUntil)
         {
             yield return(null);
         }
     }
     mRefreshingSplineNodes = false;
     yield break;
 }
示例#9
0
    //generate the control points for b spline,internal use
    //r1 = inner radius, r2 = outter radius, n = number of points
    void SplineRegenerator(int n = 10)
    {
        if (_spline == null)
        {
            _spline = this.GetComponent <Spline>();
        }

        RemoveNullNodes();

        _spline.autoClose = true;

        Vector2[] pt     = new Vector2 [2 * n];
        float     deltaA = 360f / n;

        cycleLength = 1f / n;

        Vector2 vi = Vector2.up * radius_inner;
        Vector2 vo = Vector2.up * radius_outter;

        vo = Quaternion.Euler(0f, 0f, deltaA * 0.5f) * vo;

        Quaternion deltaQ = Quaternion.Euler(0f, 0f, deltaA);

        for (int i = 0; i < n; i++)
        {
            pt[i * 2]     = Pos2 + vi;
            pt[i * 2 + 1] = Pos2 + vo;
            vi            = deltaQ * vi;
            vo            = deltaQ * vo;
        }

        int curNodeCont = _spline.splineNodesArray.Count;

        if (curNodeCont < 2 * n)
        {
            for (int i = 0; i < 2 * n; i++)
            {
                //if we exceed the no of existing nodes we need to create new node
                if (i >= curNodeCont)
                {
                    _spline.AddSplineNode(_spline.SplineNodes[_spline.splineNodesArray.Count - 1]);
                    _spline.splineNodesArray[i].transform.parent = this.transform;
                }
            }
        }
        else if (curNodeCont > 2 * n)
        {
            for (int i = curNodeCont - 1; i >= 2 * n; i--)
            {
                _spline.RemoveSplineNode(_spline.splineNodesArray[i]);
                //DestroyImmediate(_spline.splineNodesArray[i].gameObject); dont know why it doesnt work.
            }
        }

        for (int i = 0; i < 2 * n; i++)
        {
            _spline.splineNodesArray[i].Position = pt[i];
        }

        RemoveNullNodes();
    }