// initializes the object
    protected virtual bool Init()
    {
        // don't execute OnGUI behavior, for performance
        this.useGUILayout = false;

        #region error checking
        // make sure we have a VCTouchController
        if (VCTouchController.Instance == null)
        {
            Debug.LogWarning("Cannot find VCTouchController!\nVirtualControls requires a gameObject which has VCTouchController component attached in scene. Adding one for you...");
            //gameObject.AddComponent<VCTouchController>();
            VCUtils.AddTouchController(gameObject);
        }

        // make sure the movingPart is specified
        if (!movingPart)
        {
            VCUtils.DestroyWithError(gameObject, "movingPart is null, VCAnalogJoystick requires it to be assigned to a gameObject! Destroying this control.");
            return(false);
        }

        // make sure rangeX is positive
        if (this.RangeX <= 0.0f)
        {
            VCUtils.DestroyWithError(gameObject, "rangeMin must be less than rangeMax!  Destroying this control.");
            return(false);
        }

        // make sure rangeY is positive
        if (this.RangeY <= 0.0f)
        {
            VCUtils.DestroyWithError(gameObject, "rangeMin must be less than rangeMax!  Destroying this control.");
            return(false);
        }
        #endregion

        if (basePart == null)
        {
            basePart = this.gameObject;
        }

        if (colliderObject == null)
        {
            colliderObject = movingPart;
        }

        _deltaPixels             = new Vector2();
        _dragDeltaMagnitudeMaxSq = dragDeltaMagnitudeMaxPixels * dragDeltaMagnitudeMaxPixels;

        InitCollider(colliderObject);
        InitOriginValues();
        TapCount = 0;

        AddInstance();

        return(true);
    }
Esempio n. 2
0
 protected virtual bool Init()
 {
     base.useGUILayout = false;
     if (VCTouchController.Instance == null)
     {
         LogSystem.LogWarning(new object[]
         {
             "Cannot find VCTouchController!\nVirtualControls requires a gameObject which has VCTouchController component attached in scene. Adding one for you..."
         });
         VCUtils.AddTouchController(base.gameObject);
     }
     if (!this.movingPart)
     {
         VCUtils.DestroyWithError(base.gameObject, "movingPart is null, VCAnalogJoystick requires it to be assigned to a gameObject! Destroying this control.");
         return(false);
     }
     if (this.RangeX <= 0f)
     {
         VCUtils.DestroyWithError(base.gameObject, "rangeMin must be less than rangeMax!  Destroying this control.");
         return(false);
     }
     if (this.RangeY <= 0f)
     {
         VCUtils.DestroyWithError(base.gameObject, "rangeMin must be less than rangeMax!  Destroying this control.");
         return(false);
     }
     if (this.basePart == null)
     {
         this.basePart = base.gameObject;
     }
     if (this.colliderObject == null)
     {
         this.colliderObject = this.movingPart;
     }
     this._deltaPixels             = Vector2.zero;
     this._dragDeltaMagnitudeMaxSq = this.dragDeltaMagnitudeMaxPixels * this.dragDeltaMagnitudeMaxPixels;
     base.InitCollider(this.colliderObject);
     this.InitOriginValues();
     this.TapCount = 0;
     this.AddInstance();
     return(true);
 }