コード例 #1
0
        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);
 }