Ejemplo n.º 1
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);
        }
    }
Ejemplo n.º 2
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);
    }
        private void Start()
        {
            GameObject sphere = GameObject.CreatePrimitive(PrimitiveType.Sphere);

            sphere.transform.position = transform.position;
            RadialSpring spring = SpringComponent.Create <RadialSpring>("Radial");

            spring.transform.position = transform.position;
            spring.transform.parent   = transform;
            sphere.transform.parent   = spring.transform;

            root = spring;
        }
Ejemplo n.º 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);
    }
Ejemplo n.º 5
0
    //public IReadOnlyWrapper<Vector3> GetPositionRef()
    //{
    //    return position;
    //}
    //public IReadOnlyWrapper<Quaternion> GetRotationRef()
    //{
    //    return rotation;
    //}

    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);
    }
Ejemplo n.º 6
0
        protected override void Init()
        {
            if (isOwner)
            {
                movementController = gameObject.GetComponent <MovementController>();
                platformController = gameObject.GetComponent <PlatformController>();
            }
            else
            {
                spring = SpringComponent.Create <SphericalSpring>("spring", null);
                spring.transform.parent        = transform;
                spring.transform.localPosition = Vector3.zero;
                spring.dynamicStrength         = 0.00000001f;


                GameObject sphere = GameObject.CreatePrimitive(PrimitiveType.Sphere);
                DestroyImmediate(sphere.GetComponent <Collider>());
                sphere.transform.parent        = spring.transform;
                sphere.transform.localPosition = Vector3.zero;

                movementController = gameObject.AddComponent <MovementController>();
                movementController.OnCoordinateSpaceDelta += spring.PropegateDelta;

                gameObject.AddComponent <SphereCollider>();

                platformController = gameObject.AddComponent <PlatformController>();
            }
            try
            {
                targetInput = movementController.targetInput;
            }
            catch (Exception e)
            {
                Debug.LogError("Movement Controller Error: " + owner + " : " + isOwner);
                Debug.LogError(e);
            }

            oldPosition = transform.position;
        }
Ejemplo n.º 7
0
        void Start()
        {
            movementController = GetComponent <MovementController>();
            movementController.OnCoordinateSpaceDelta += OnCoordinateSpaceDelta;
            movementController.OnNewCoordinateSpace   += OnNewCoordinateSpace;

            var springObject = new GameObject("Axial");

            springObject.transform.parent        = transform;
            springObject.transform.localPosition = Vector3.zero;
            springObject.transform.localRotation = Quaternion.identity;

            var spring = springObject.AddComponent <AxialSpring>();

            spring.axis            = Vector3.up;
            spring.dynamicStrength = 0.00000001f;

            var gyroObject = new GameObject("Gyro");

            gyroObject.transform.parent        = springObject.transform;
            gyroObject.transform.localPosition = Vector3.zero;
            gyroObject.transform.localRotation = Quaternion.identity;

            var gyro = gyroObject.AddComponent <GyroSpring>();

            gyro.staticStrength = 10f;

            var camera = GetComponentInChildren <Camera>();

            camera.transform.parent        = gyroObject.transform;
            camera.transform.localPosition = Vector3.zero;
            camera.transform.localRotation = Quaternion.identity;

            root = SpringComponent.AutoLink(springObject);

            CEventSystem.AddEventListener(EventChannel.input, EventPlayerNumberChannel.player1, this);
        }
Ejemplo n.º 8
0
 public static T Create <T>(string name = "", SpringComponent parent = null) where T : SpringComponent
 {
     return(new GameObject().AddComponent <T>()._Init <T>(name, parent));
 }
Ejemplo n.º 9
0
 private void Start()
 {
     root = SpringComponent.AutoLink(gameObject);
     root.Reset(transform.position, transform.rotation);
 }