public void CreateWires() { List <GameObject> gameObjects = new List <GameObject>(); int count = 0; Material wireMaterial = null; foreach (KeyValuePair <string, List <PowerlineNode> > wire in this.wires) { foreach (PowerlineNode value in wire.Value) { MegaWireConnectionHelper component = value.GetComponent <MegaWireConnectionHelper>(); if (!component) { continue; } if (gameObjects.Count != 0) { GameObject item = gameObjects[gameObjects.Count - 1]; if (value.WireMaterial != wireMaterial || component.connections.Count != count || (item.transform.position - value.transform.position).sqrMagnitude > value.MaxDistance * value.MaxDistance) { this.CreateWire(wire.Key, gameObjects, wireMaterial); gameObjects.Clear(); } } else { wireMaterial = value.WireMaterial; count = component.connections.Count; } gameObjects.Add(value.gameObject); } this.CreateWire(wire.Key, gameObjects, wireMaterial); gameObjects.Clear(); } }
public override void OnInspectorGUI() { MegaWireConnectionHelper mod = (MegaWireConnectionHelper)target; undoManager.CheckUndo(); #if UNITY_5_3 || UNITY_5_4 || UNITY_5_5 || UNITY_5_6 || UNITY_2017 #else EditorGUIUtility.LookLikeControls(); #endif mod.showgizmo = EditorGUILayout.Toggle("Show Connections", mod.showgizmo); if (GUILayout.Button("Add Wire")) { MegaWireConnectionDef cdef = new MegaWireConnectionDef(); if (mod.connections.Count > 0) { MegaWireConnectionDef last = mod.connections[mod.connections.Count - 1]; cdef.inOffset = last.inOffset; cdef.outOffset = last.outOffset; cdef.radius = last.radius; } mod.connections.Add(cdef); } for (int i = 0; i < mod.connections.Count; i++) { MegaWireConnectionDef con = mod.connections[i]; EditorGUILayout.BeginVertical("box"); con.radius = EditorGUILayout.FloatField("Radius", con.radius); con.outOffset = EditorGUILayout.Vector3Field("Out Offset", con.outOffset); con.inOffset = EditorGUILayout.Vector3Field("In Offset", con.inOffset); if (GUILayout.Button("Delete")) { if (mod.connections.Count > 1) { mod.connections.RemoveAt(i); } } EditorGUILayout.EndVertical(); } if (GUI.changed) { EditorUtility.SetDirty(target); } undoManager.CheckDirty(); }
public void Copy(MegaWire from, MegaWireConnectionHelper helper) { fudge = from.fudge; spring = from.spring; damp = from.damp; timeStep = from.timeStep; Mass = from.Mass; gravity = from.gravity; airdrag = from.airdrag; massRand = from.massRand; points = from.points; iters = from.iters; wind = from.wind; material = from.material; disableOnNotVisible = from.disableOnNotVisible; disableDist = from.disableDist; disableOnDistance = from.disableOnDistance; stretch = from.stretch; awakeTime = from.awakeTime; gizmoColor = from.gizmoColor; displayGizmo = from.displayGizmo; disableOnDistance = from.disableOnDistance; distfromcamera = from.distfromcamera; frameWait = from.frameWait; frameNum = from.frameNum; stiffnessSprings = from.stiffnessSprings; stiffrate = from.stiffrate; stiffdamp = from.stiffdamp; lengthConstraints = from.lengthConstraints; connections.Clear(); if (helper) { for (int i = 0; i < helper.connections.Count; i++) { connections.Add(new MegaWireConnectionDef(helper.connections[i])); } } else { for (int i = 0; i < from.connections.Count; i++) { connections.Add(new MegaWireConnectionDef(from.connections[i])); } } strandedMesher.Copy(from.strandedMesher); }
public void OnSceneGUI() { MegaWireConnectionHelper mod = (MegaWireConnectionHelper)target; if (mod.showgizmo) { Handles.matrix = mod.transform.localToWorldMatrix; for (int i = 0; i < mod.connections.Count; i++) { MegaWireConnectionDef con = mod.connections[i]; con.inOffset = Handles.PositionHandle(con.inOffset, Quaternion.identity); con.outOffset = Handles.PositionHandle(con.outOffset, Quaternion.identity); Handles.Label(con.inOffset, "in " + i); Handles.Label(con.outOffset, "out " + i); } } }
public void CreateWires() { List <GameObject> objects = new List <GameObject>(); int num = 0; Material material = (Material)null; foreach (KeyValuePair <string, List <PowerlineNode> > wire in this.wires) { foreach (PowerlineNode powerlineNode in wire.Value) { MegaWireConnectionHelper component = (MegaWireConnectionHelper)((Component)powerlineNode).GetComponent <MegaWireConnectionHelper>(); if (Object.op_Implicit((Object)component)) { if (objects.Count == 0) { material = powerlineNode.WireMaterial; num = ((List <MegaWireConnectionDef>)component.connections).Count; } else { GameObject gameObject = objects[objects.Count - 1]; if (!Object.op_Inequality((Object)powerlineNode.WireMaterial, (Object)material) && ((List <MegaWireConnectionDef>)component.connections).Count == num) { Vector3 vector3 = Vector3.op_Subtraction(gameObject.get_transform().get_position(), ((Component)powerlineNode).get_transform().get_position()); if ((double)((Vector3) ref vector3).get_sqrMagnitude() <= (double)powerlineNode.MaxDistance * (double)powerlineNode.MaxDistance) { goto label_10; } } this.CreateWire(wire.Key, objects, material); objects.Clear(); } label_10: objects.Add(((Component)powerlineNode).get_gameObject()); } } this.CreateWire(wire.Key, objects, material); objects.Clear(); } }
// each wire length should have a very simple script attached that can do onvisible etc // to turn off the updates, other than that all updates should be done from MegaWire static public MegaWire Create(MegaWire wire, List <GameObject> objs, Material mat, string name, MegaWire copyfrom, float wiresize, float str) { //MegaWire wire = null; if (objs != null && objs.Count > 1) { GameObject newwire = null; if (wire == null) { newwire = new GameObject(); newwire.name = name; wire = newwire.AddComponent <MegaWire>(); wire.material = mat; wire.stretch = str; } else { newwire = wire.gameObject; } wire.poles.Clear(); wire.spans.Clear(); wire.connections.Clear(); wire.poles.Add(objs[0].transform); bool hide = true; if (copyfrom) { hide = copyfrom.hidespans; } // Make the connections, each connection is a new gameobject child of the wire object for (int i = 0; i < objs.Count - 1; i++) { GameObject pole = new GameObject(); if (hide) { pole.hideFlags = HideFlags.HideInHierarchy | HideFlags.HideInInspector | HideFlags.NotEditable; } pole.name = name + " Span Mesh " + i; pole.transform.parent = newwire.transform; MegaWireSpan span = pole.AddComponent <MegaWireSpan>(); span.start = objs[i].transform; span.end = objs[i + 1].transform; MeshFilter mf = pole.GetComponent <MeshFilter>(); mf.sharedMesh = new Mesh(); MeshRenderer mr = pole.GetComponent <MeshRenderer>(); Material[] mats = new Material[1]; mats[0] = wire.material; mr.sharedMaterials = mats; span.mesh = mf.sharedMesh; span.mesh.name = name + " Wire Mesh " + i; span.Init(wire); wire.spans.Add(span); wire.poles.Add(objs[i + 1].transform); } MegaWireConnectionHelper helper = objs[0].GetComponent <MegaWireConnectionHelper>(); if (copyfrom) { wire.Copy(copyfrom, helper); } else { // Check if any pole has a helper on it, if so use that if (helper) { wire.Copy(wire, helper); } else { // Add the first connection MegaWireConnectionDef con = new MegaWireConnectionDef(); wire.connections.Add(con); } } if (wiresize != 1.0f) { for (int i = 0; i < wire.connections.Count; i++) { wire.connections[i].radius *= wiresize; } } wire.Init(); } return(wire); }