示例#1
0
    /// <summary>
    /// Execute the action; actObj.
    /// </summary>
    /// <param name='actObj'>
    /// Object doing the action
    /// </param>
    override public void Run(GameObject obj, ActionData data)
    {
        if (startObject == null)
        {
            GameObject intersectedObj = PickUtil.GetObjectUnderMouseRay();
            if (intersectedObj != null)
            {
                startObject = intersectedObj.GetComponent <Rigidbody>();
                if (startObject != null)
                {
//					float hitT;
//					anchor = PickUtil.GetXYPlaneHitPoint(out hitT) - intersectedObj.transform.position;
                }
            }
        }
        else
        {
            GameObject obj2 = PickUtil.GetObjectUnderMouseRay();
            if (obj2 != null && obj2 != startObject)
            {
                Rigidbody body2 = obj2.GetComponent <Rigidbody>();
                if (body2 != null)
                {
//					float hitT;
//					Vector3 anchor2 = PickUtil.GetXYPlaneHitPoint(out hitT) - obj2.transform.position;

                    FixedJoint joint = startObject.gameObject.AddComponent <FixedJoint>();
//					joint.anchor = anchor;
                    joint.connectedBody = body2;
//					joint.connectedAnchor = anchor2;
                }
            }
        }
    }
示例#2
0
    /// <summary>
    /// Returns the shooting direction.
    /// </summary>
    /// <param name='obj'>
    /// Object.
    /// </param>
    override protected Vector3 GetDirection(GameObject obj, ActionData data)
    {
        float   hitT;
        Vector3 mousePos = data.mousePos == Vector3.zero ?
                           PickUtil.GetXYPlaneHitPoint(out hitT) : data.mousePos;
        Vector3 direction = mousePos - obj.transform.position;

        direction.Normalize();
        return(direction);
    }
//	private void CmdRun(GameObject obj) {
//		int id = ObjectManager.Instance.GetId(obj);
//		_data.mousePos = ActionInput.GetMousePos(_data);
//		if (isServer) {
//			RpcRun(id, _data);
//		} else {
//			CmdRun(id, _data);
//		}
//	}
//
//	[Command]
//	virtual public void CmdRun(int id, ActionData data) {
//		Run(id, data);
//	}
//
//	[ClientRpc]
//	virtual public void RpcRun(int id, ActionData data) {
//		Run(id, data);
//	}

    public static Vector3 GetMousePos(ActionData?data)
    {
        Ray mouseRay = data == null?
                       PickUtil.GetMouseRay() : PickUtil.GetScreenRay(new Vector2(Input.mousePosition.x, Input.mousePosition.y));

        float   hitT;
        Vector3 pos = PickUtil.GetXZPlaneHitPointForRay(out hitT, mouseRay);

        return(pos);
    }
示例#4
0
    /// <summary>
    /// Returns the position for the shot to start at.
    /// </summary>
    override protected Vector3 GetPosition(GameObject obj, Vector3 shotDirection, ActionData data)
    {
        float   hitT;
        Vector3 mousePos = data.mousePos == Vector3.zero ? PickUtil.GetXZPlaneHitPoint(out hitT) : data.mousePos;

        if (tileSize > 0)
        {
            mousePos = new Vector3((int)(mousePos.x / tileSize) * tileSize, 0, (int)(mousePos.z / tileSize) * tileSize);
        }
        return(mousePos);
    }
示例#5
0
    /// <summary>
    /// Returns the position for the shot to start at.
    /// </summary>
    override protected Vector3 GetPosition(GameObject obj, Vector3 shotDirection, ActionData data)
    {
        float   hitT;
        Vector3 pos = PickUtil.GetXYPlaneHitPoint(out hitT);

        if (tileSize > 0)
        {
            pos = new Vector3((int)(pos.x / tileSize) * tileSize, (int)(pos.y / tileSize) * tileSize, 0);
        }
        return(pos);
    }
示例#6
0
    override public void Run(GameObject obj, ActionData data)
    {
        Follow follow = GetComponent <Follow>();

        if (follow != null)
        {
            GameObject intersectedObj = PickUtil.GetObjectUnderMouseRay();
            if (intersectedObj != null)
            {
                follow.target = intersectedObj;
            }
        }
    }
示例#7
0
    /// <summary>
    /// Execute the action; actObj.
    /// </summary>
    /// <param name='actObj'>
    /// Object doing the action
    /// </param>
    override public void Run(GameObject obj, ActionData data)
    {
        GameObject intersectedObj = PickUtil.GetObjectUnderMouseRay();

        if (intersectedObj != null)
        {
            ApplyTorque applyTorque = intersectedObj.AddComponent <ApplyTorque> ();
            if (torque != Vector3.zero)
            {
                applyTorque.torque = torque;
            }
        }
    }
示例#8
0
 /// <summary>
 /// Returns the shooting direction.
 /// </summary>
 /// <param name='obj'>
 /// Object.
 /// </param>
 override protected Vector3 GetDirection(GameObject obj, ActionData data)
 {
     return(PickUtil.GetMouseRay().direction);
 }