Projekt

Obecné

Profil

Stáhnout (1.27 KB) Statistiky
| Větev: | Tag: | Revize:
1
using UnityEngine;
2

    
3
namespace DeltaRobotVr.Components
4
{
5
    /// <summary>
6
    /// A generic implementation of vector visualization. The vector is determined by the <c>GetVector</c> method.
7
    /// </summary>
8
    public abstract class AbstractArrow : MonoBehaviour
9
    {
10
        public float lengthMultiplier = 2;
11
        protected Renderer objectRenderer;
12

    
13
        private void Start()
14
        {
15
            objectRenderer = GetComponent<Renderer>();
16
        }
17

    
18
        void Update()
19
        {
20
            if (Client.Instance.IsConnected)
21
            {
22
                Vector3 v = Single3Utils.ToVector3(GetVector());
23
                
24
                var t = transform;
25
                var zs = v.magnitude * lengthMultiplier;
26
                t.rotation = Quaternion.FromToRotation(Vector3.forward, v);
27
                t.localScale = new Vector3(1, 1, zs);
28
                
29
                // If scale is 0, hide arrow
30
                // Seems fine without delta
31
                if (objectRenderer.enabled == (zs == 0.0f))
32
                {
33
                    objectRenderer.enabled = !(zs == 0.0f);
34
                }
35
            }
36
        }
37

    
38
        /// <summary>
39
        /// Gets the vector that this component renders.
40
        /// </summary>
41
        protected abstract Single3 GetVector();
42
    }
43
}
(1-1/12)