private void CreateWire(string name, List <GameObject> objects, Material material)
 {
     if (objects.Count >= 3 && material != null)
     {
         MegaWire megaWire = MegaWire.Create(null, objects, material, "Powerline Wires", null, 1f, 0.1f);
         if (megaWire)
         {
             megaWire.enabled = false;
             megaWire.RunPhysics(megaWire.warmPhysicsTime);
             megaWire.gameObject.SetHierarchyGroup(name, true, false);
         }
     }
 }
Exemple #2
0
    private void CreateWire(string name, List <GameObject> objects, Material material)
    {
        if (objects.Count < 3 || !Object.op_Inequality((Object)material, (Object)null))
        {
            return;
        }
        MegaWire megaWire = MegaWire.Create((MegaWire)null, objects, material, "Powerline Wires", (MegaWire)null, 1f, 0.1f);

        if (!Object.op_Implicit((Object)megaWire))
        {
            return;
        }
        ((Behaviour)megaWire).set_enabled(false);
        megaWire.RunPhysics((float)megaWire.warmPhysicsTime);
        ((Component)megaWire).get_gameObject().SetHierarchyGroup(name, true, false);
    }
    public void Rebuild()
    {
        CalcLength();
        if (waypoints.Count > 1 && pole)
        {
            update = false;

            //GameObject oldwire = null;
            MegaWire oldwire = transform.GetComponentInChildren <MegaWire>();
            // Destroy all children
            MegaWireConnectionHelper[] spans = transform.GetComponentsInChildren <MegaWireConnectionHelper>();

            for (int i = 0; i < spans.Length; i++)
            {
                if (Application.isEditor)
                {
                    DestroyImmediate(spans[i].gameObject);
                }
                else
                {
                    Destroy(spans[i].gameObject);
                }
            }

            MegaWireSpan[] spans1 = transform.GetComponentsInChildren <MegaWireSpan>();

            for (int i = 0; i < spans1.Length; i++)
            {
                if (Application.isEditor)
                {
                    DestroyImmediate(spans1[i].gameObject);
                }
                else
                {
                    Destroy(spans1[i].gameObject);
                }
            }

#if false
            while (transform.childCount > 0)
            {
                GameObject go = transform.GetChild(0).gameObject;

                // Dont destroy wire object
                MegaWire wire = go.GetComponent <MegaWire>();

                if (!wire)
                {
                    if (Application.isEditor)
                    {
                        DestroyImmediate(go);
                    }
                    else
                    {
                        Destroy(go);
                    }
                }
                else
                {
                    oldwire = go;
                }
            }
#endif

            int polecount = (int)((pathlength * length) / spacing);

            float alpha = start;
            float da    = length / polecount;

            if (closed)
            {
                polecount--;
            }

            poles.Clear();

            Random.seed = seed;

            float spacealpha = ((spacing / (pathlength * length)) / 2.0f) * spacingVariation;

            for (int i = 0; i <= polecount; i++)
            {
                float a = alpha;

                if (i != 0 && i != polecount)
                {
                    a = alpha + (Random.Range(-1.0f, 1.0f) * spacealpha);
                }

                Vector3 p  = InterpCurve3D(a);
                Vector3 p1 = InterpCurve3D(a + 0.001f);

                Vector3 poff = Vector3.zero;
                poff.y = Random.Range(0.0f, 1.0f) * positionVariation.y;
                poff.z = Random.Range(-1.0f, 1.0f) * positionVariation.z;

                Vector3 dir = (p1 - p).normalized;

                Vector3 outline = Vector3.Cross(dir, Vector3.up) * (offset + poff.z);

                p  += outline;
                p1 += outline;

                Quaternion hitrot = Quaternion.identity;

                if (conform)
                {
                    Ray     ray    = new Ray();
                    Vector3 origin = p;
                    origin.y = 1000.0f;

                    ray.origin    = origin;
                    ray.direction = Vector3.down;

                    RaycastHit[] hits = Physics.RaycastAll(ray);

                    if (hits.Length > 0)
                    {
                        int hindex = 0;
                        p = hits[hindex].point;

                        for (int j = 1; j < hits.Length; j++)
                        {
                            if (hits[j].point.y > p.y)
                            {
                                hindex = j;
                                p      = hits[hindex].point;
                            }
                        }

                        Vector3 norm1 = Vector3.Lerp(hits[hindex].normal, Vector3.up, upright).normalized;
                        hitrot = Quaternion.FromToRotation(Vector3.up, norm1);
                    }
                }
                else
                {
                }

                Vector3 relativePos = p1 - p;

                relativePos.y = 0.0f;

                Quaternion rot = Quaternion.LookRotation(relativePos, Vector3.up);

                Vector3 rrot = Vector3.zero;
                rrot.x = Random.Range(-1.0f, 1.0f) * rotateVariation.x;
                rrot.y = Random.Range(-1.0f, 1.0f) * rotateVariation.y;
                rrot.z = Random.Range(-1.0f, 1.0f) * rotateVariation.z;

                Quaternion erot = Quaternion.Euler(rotate + rrot);

                p.y -= poff.y;

                GameObject go = (GameObject)GameObject.Instantiate(pole, p, hitrot * rot * erot);                       //rot * hitrot * erot);
                go.name = name + " Pole " + i;

                go.transform.parent = transform;

                alpha += da;
                poles.Add(go);
            }

            if (length >= 0.99999f && closed)
            {
                poles.Add(poles[0]);
            }

            if (addwires)
            {
                if (reverseWire)
                {
                    poles.Reverse();
                }

                MegaWire wire = MegaWire.Create(oldwire, poles, material, name + " Wires", copyfrom, wireSizeMult, stretch);
                if (wire)
                {
                    wire.transform.parent = transform;
                }
            }
        }
    }
Exemple #4
0
    void OnGUI()
    {
        scroll = EditorGUILayout.BeginScrollView(scroll);

        if (picking)
        {
            if (GUILayout.Button("Stop Picking"))
            {
                picking = false;
            }
        }
        else
        {
            if (GUILayout.Button("Start Picking"))
            {
                picking = true;
                lastsel = null;
                // Ask if clear or add

                if (selection.Count > 0)
                {
                    bool opt = EditorUtility.DisplayDialog("Add or Replace", "Do you want to Add to or Replace selection", "Add", "Replace");

                    if (opt == false)
                    {
                        selection.Clear();
                    }
                }
            }
        }

        // If we have a wire object selected then replace the selection
        if (GUILayout.Button("Create Wire"))
        {
            picking = false;
            MegaWire wire = MegaWire.Create(null, selection, material, wirename, copyfrom, 1.0f, 1.0f);

            copyfrom = wire;
            selection.Clear();
        }

        wirename = EditorGUILayout.TextField("Wire Name", wirename);
        material = (Material)EditorGUILayout.ObjectField("Material", material, typeof(Material), true);
        copyfrom = (MegaWire)EditorGUILayout.ObjectField("Copy From", copyfrom, typeof(MegaWire), true);

        EditorGUILayout.BeginVertical("box");
        EditorGUILayout.LabelField("Current Selection");
        for (int i = 0; i < selection.Count; i++)
        {
            EditorGUILayout.LabelField(i + ": " + selection[i].name);
        }

        EditorGUILayout.EndVertical();

        showarrows = EditorGUILayout.Foldout(showarrows, "Arrow Params");

        if (showarrows)
        {
            units      = (MegaWireUnits)EditorGUILayout.EnumPopup("Units", units);
            unitsScale = EditorGUILayout.FloatField("Units Scale", unitsScale);

            arrowwidth  = EditorGUILayout.FloatField("Arrow Width", arrowwidth);
            arrowlength = EditorGUILayout.FloatField("Arrow Length", arrowlength);
            arrowoff    = EditorGUILayout.Slider("Arrow Offset", arrowoff, 0.0f, 1.0f);
            vertStart   = EditorGUILayout.FloatField("Vert Start", vertStart);
            vertLength  = EditorGUILayout.FloatField("Vert Length", vertLength);

            dashdist = EditorGUILayout.FloatField("Dash Dist", dashdist);
            lineCol  = EditorGUILayout.ColorField("Line Color", lineCol);
            arrowCol = EditorGUILayout.ColorField("Arrow Color", arrowCol);
            otherCol = EditorGUILayout.ColorField("Other Color", otherCol);
            dashCol  = EditorGUILayout.ColorField("Dash Color", dashCol);
        }

        EditorGUILayout.EndScrollView();
    }
Exemple #5
0
    public void Rebuild()
    {
        if (path && pole)
        {
            update = false;

            MegaWire oldwire = transform.GetComponentInChildren <MegaWire>();

            // Destroy all children
            while (transform.childCount > 0)
            {
                GameObject go = transform.GetChild(0).gameObject;

                if (Application.isEditor)
                {
                    DestroyImmediate(go);
                }
                else
                {
                    Destroy(go);
                }
            }

            int polecount = (int)((path.splines[curve].length * length) / spacing);

            float alpha = start;
            float da    = length / polecount;

            if (path.splines[curve].closed)
            {
                polecount--;
            }

            poles.Clear();
#if UNITY_5_4 || UNITY_5_5 || UNITY_5_6 || UNITY_2017
            Random.InitState(seed);
#else
            Random.seed = seed;
#endif

            float spacealpha = ((spacing / (path.splines[curve].length * length)) / 1.0f) * spacingVariation;

            // mmm need upright in here
            for (int i = 0; i <= polecount; i++)
            {
                float a = alpha;

                if (i != 0 && i != polecount - 1)
                {
                    a = alpha + (Random.Range(-1.0f, 1.0f) * spacealpha);
                }

                Vector3 p  = path.transform.TransformPoint(path.InterpCurve3D(curve, a, true));
                Vector3 p1 = path.transform.TransformPoint(path.InterpCurve3D(curve, a + 0.001f, true));

                Vector3 poff = Vector3.zero;
                poff.y = Random.Range(0.0f, 1.0f) * positionVariation.y;
                poff.z = Random.Range(-1.0f, 1.0f) * positionVariation.z;

                Vector3 dir = (p1 - p).normalized;

                Vector3 outline = Vector3.Cross(dir, Vector3.up) * (offset + poff.z);

                p  += outline;
                p1 += outline;

                //Vector3 up = Vector3.up;
                //Vector3 norm = up;

                Quaternion hitrot = Quaternion.identity;

                if (conform)
                {
                    Ray     ray    = new Ray();
                    Vector3 origin = p;
                    origin.y = 1000.0f;

                    ray.origin    = origin;
                    ray.direction = Vector3.down;

                    RaycastHit[] hits = Physics.RaycastAll(ray);

                    if (hits.Length > 0)
                    {
                        int hindex = 0;
                        p = hits[hindex].point;

                        for (int j = 1; j < hits.Length; j++)
                        {
                            if (hits[j].point.y > p.y)
                            {
                                hindex = j;
                                p      = hits[hindex].point;
                            }
                        }

                        Vector3 norm1 = Vector3.Lerp(hits[hindex].normal, Vector3.up, upright).normalized;
                        hitrot = Quaternion.FromToRotation(Vector3.up, norm1);
                    }
                }
                else
                {
                }

                Vector3 relativePos = p1 - p;

                relativePos.y = 0.0f;                   //*= upright;

                Quaternion rot = Quaternion.LookRotation(relativePos, Vector3.up);

                Vector3 rrot = Vector3.zero;
                rrot.x = Random.Range(-1.0f, 1.0f) * rotateVariation.x;
                rrot.y = Random.Range(-1.0f, 1.0f) * rotateVariation.y;
                rrot.z = Random.Range(-1.0f, 1.0f) * rotateVariation.z;

                Quaternion erot = Quaternion.Euler(rotate + rrot);

                p.y -= poff.y;

                GameObject go = (GameObject)GameObject.Instantiate(pole, p, hitrot * rot * erot);                       //rot * hitrot * erot);
                go.name = "Pole " + i;

                go.transform.parent = transform;

                alpha += da;
                poles.Add(go);
            }

            if (length >= 0.99999f && path.splines[curve].closed)
            {
                poles.Add(poles[0]);
            }

            if (addwires)
            {
                if (reverseWire)
                {
                    poles.Reverse();
                }

                MegaWire wire = MegaWire.Create(oldwire, poles, material, "Wires", copyfrom, wireSizeMult, stretch);

                if (wire)
                {
                    wire.transform.parent = transform;
                }
            }
        }
    }