Example #1
0
        public void CreateSegments(List <Nexus> sceneNexuses)
        {
            GameObject segParent = new GameObject("Segment Parent");

            segParent.transform.SetParent(sceneNexuses[0].transform.parent, false);
            segParent.transform.localPosition = Vector3.zero;


            foreach (Nexus nexus in sceneNexuses)
            {
                foreach (Nexus.CnxnInfo cnxn in nexus.Cnxns)
                {
                    if (cnxn.Status == Nexus.CnxnStatus.Unconnected)
                    {
                        switch (cnxn.Type)
                        {
                        case Nexus.CnxnType.Web:
#if UNITY_EDITOR
                            GameObject newSeg = (GameObject)PrefabUtility.InstantiatePrefab(WebSegmentPrefab, segParent.transform);
#else
                            GameObject newSeg = Instantiate(WebSegmentPrefab, segParent.transform);
#endif
                            newSeg.transform.position = nexus.transform.position;
                            newSeg.transform.LookAt(cnxn.ConnectedTo.transform);
                            float dist = Vector3.Distance(nexus.transform.position, cnxn.ConnectedTo.transform.position);
                            newSeg.transform.localScale = new Vector3(
                                newSeg.transform.localScale.x,
                                newSeg.transform.localScale.y,
                                dist * (1 / newSeg.transform.lossyScale.z));

                            //float angleDiff = Vector3.SignedAngle( newSeg.transform.up, Vector3.forward, Vector3.right );
                            //newSeg.transform.localRotation = Quaternion.Euler( new Vector3(
                            //	newSeg.transform.localRotation.eulerAngles.x,
                            //	newSeg.transform.localRotation.eulerAngles.y,
                            //	angleDiff
                            //	) );

                            newSeg.transform.rotation = Quaternion.FromToRotation(newSeg.transform.up, -Vector3.forward) * newSeg.transform.rotation;

                            Segment newSegSeg = newSeg.GetComponent <Segment>();
                            newSegSeg.Parents    = new Nexus[] { nexus, cnxn.ConnectedTo };
                            newSegSeg.MyCnxnType = cnxn.Type;

                            cnxn.Status  = Nexus.CnxnStatus.Connected;
                            cnxn.Segment = newSeg.GetComponent <Segment>();
                            Nexus.CnxnInfo childCnxn = cnxn.ConnectedTo.Cnxns.Find(
                                cnxnInfo => cnxnInfo.ConnectedTo == nexus
                                );
                            childCnxn.Status  = Nexus.CnxnStatus.Connected;
                            childCnxn.Segment = newSeg.GetComponent <Segment>();
                            break;
                        }
                    }
                }
            }
        }
Example #2
0
        public void ConnectNexuses(Nexus first, Nexus second)
        {
            Nexus.CnxnInfo firstCnxn  = new Nexus.CnxnInfo();
            Nexus.CnxnInfo secondCnxn = new Nexus.CnxnInfo();

            firstCnxn.ConnectedTo  = second;
            secondCnxn.ConnectedTo = first;
            firstCnxn.Status       = secondCnxn.Status = Nexus.CnxnStatus.Unconnected;
            firstCnxn.Type         = secondCnxn.Type = Nexus.CnxnType.Web;

            first.Cnxns.Add(firstCnxn);
            second.Cnxns.Add(secondCnxn);
        }