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);
        }
예제 #2
0
        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);
            }
        }
예제 #3
0
        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);
        }
예제 #4
0
        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);
        }
예제 #5
0
        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);
        }
예제 #6
0
 public static T Create <T>(string name = "", SpringComponent parent = null) where T : SpringComponent
 {
     return(new GameObject().AddComponent <T>()._Init <T>(name, parent));
 }
예제 #7
0
 private void Start()
 {
     root = SpringComponent.AutoLink(gameObject);
     root.Reset(transform.position, transform.rotation);
 }