public void OnDrawGizmos() { //compute delta time float deltaTime = 0f; if (time == -1f) { time = (float)EditorApplication.timeSinceStartup; } deltaTime = (float)EditorApplication.timeSinceStartup - time; time = (float)EditorApplication.timeSinceStartup; if (Application.isPlaying) { deltaTime = Time.deltaTime; } else { SpringComponent.AutoUpdate(gameObject); } foreach (Transform child in transform) { var comp = child.GetComponent <SpringComponent>(); if (comp != null) { comp.Propegate(transform.position, transform.rotation, deltaTime); } } Draw(transform); }
private static void AutoUpdateScan(SpringComponent parent, GameObject gameObject) { var comp = gameObject.GetComponent <SpringComponent>(); if (comp != null) { comp.parent = parent; if (parent != null) { parent.children.Add(comp); } comp.children.Clear(); } else { comp = parent; } foreach (Transform child in gameObject.transform) { AutoUpdateScan(comp, child.gameObject); } }
private void Awake() { root = SpringComponent.Create <SpringOffset>("root"); root.transform.parent = transform; arm = SpringComponent.Create <SphericalSpring>("arm", root); rotSpring = SpringComponent.Create <RadialSpring>("rot", arm); //pos = rotSpring.GetPositionRef(); //rot = rotSpring.GetRotationRef(); cube = GameObject.CreatePrimitive(PrimitiveType.Cube); }
private T _Init <T>(string name = "", SpringComponent parent = null) where T : SpringComponent { this.name = name; if (parent != null) { this.parent = parent; parent.children.Add(this); } transform.parent = parent?.transform; return((T)this); }
public static SpringComponent AutoLink(GameObject gameObject) { SpringComponent root = gameObject.GetComponent <SpringComponent>(); if (root != null) { foreach (Transform child in gameObject.transform) { SpringComponent c = AutoLink(child.gameObject); if (c != null) { c.parent = root; root.children.Add(c); } } } return(root); }
public static T Create <T>(string name = "", SpringComponent parent = null) where T : SpringComponent { return(new GameObject().AddComponent <T>()._Init <T>(name, parent)); }
private void Start() { root = SpringComponent.AutoLink(gameObject); root.Reset(transform.position, transform.rotation); }