void CheckForRotationHandle(RaycastHit2D hit, Vector3 mousePos)
    {
        if (hit.collider != null)
        {
            RotateHandle handle = hit.collider.GetComponent <RotateHandle>();

            if (handle != null)
            {
                objectRotating = handle;
                objectRotating.InitPosition();
            }
        }
    }
    void UpdateRotatable()
    {
        if (objectRotating != null)
        {
            Vector3 mousePos = Camera.main.ScreenToWorldPoint(Input.mousePosition);
            objectRotating.SetPositionAndRotate(mousePos);

            if (Input.GetMouseButtonUp(0))
            {
                objectRotating     = null;
                skipCheckThisFrame = true;
            }
        }
    }
Exemple #3
0
        public void Init(XElement xml, Grenade grenade)
        {
            this.grenade = grenade;

            this.open        = (float?)xml.Attribute("open") ?? 30f;
            this.released    = (float?)xml.Attribute("released") ?? 150f;
            this.threshold   = (float?)xml.Attribute("threshold") ?? 27f;
            this.rotateSpeed = (float?)xml.Attribute("degreesPerSecond") ?? 100f;
            this.grip        = grenade.transform.Find((string)xml.Attribute("grip") ?? "HandleGrip")?.GetComponent <Grip>();
            var fingers = (string)xml.Attribute("fingers");

            this.audio = grenade.transform.Find((string)xml.Attribute("audio") ?? "HandleSound")?.GetComponent <AudioSource>();
            if (fingers != null)
            {
                var strings = fingers.Split(',');
                this.fingers = new float[strings.Length];
                for (int i = 0; i < strings.Length; i++)
                {
                    if (!float.TryParse(strings[i], out this.fingers[i]))
                    {
                        this.fingers[i] = 0f;
                    }
                }
            }

            if (xml.Attribute("axis") != null) // legacy handling
            {
                var legacy = new RotateHandle();
                legacy.Init(xml, this);
                elements.Add(legacy);
            }

            foreach (var el in xml.Elements())
            {
                if (Elements.TryGetValue(el.Name.LocalName, out var factory))
                {
                    var x = factory();
                    x.Init(el, this);
                    this.elements.Add(x);
                }
            }
        }