blob: 6461871c1d5677639d85610d929dec70d51b537b (
plain)
| 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
 | using UnityEngine;
using System.Collections;
using XUtliPoolLib;
using System;
public class XDragonExpedition : MonoBehaviour, IXDragonExpedition
{
    #region 接口
    public void Drag(float delta)
    {
        MoveCamera(delta);
    }
    public void  Assign(float delta)
    {
        AssignCamera(delta);
    }
    public Transform GetGO(string name)
    {
        return transform.Find(name);
    }
    public void SetLimitPos(float MinPos)
    {
        MIN_POS = MinPos;
    }
    RaycastHit[] hits = null;
    public GameObject Click()
    {
        //Vector3 pos = mCamera.ScreenToViewportPoint(Input.mousePosition);
        Ray ray = mCamera.ScreenPointToRay(Input.mousePosition);
        float dist = mCamera.farClipPlane - mCamera.nearClipPlane;
        hits = Physics.RaycastAll(ray, dist);
        for (int i = 0; i < hits.Length; ++i)
        {
            if (hits[i].collider.gameObject.name.StartsWith("building"))
                return hits[i].collider.gameObject;
        }
        return null;
    }
    public Camera GetDragonCamera()
    {
        return mCamera;
    }
    #endregion
    void Start()
    {
        curPos = mCamera.transform.localPosition;
    }
    public Camera mCamera = null;
    public float MoveSpeed = 5;
    public float MIN_POS = 0;
    public float MAX_POS = 100;
    Vector3 curPos = Vector3.zero;
    void MoveCamera(float delta)
    {
        curPos.x += delta * MoveSpeed;
        if (curPos.x < MIN_POS) curPos.x = MIN_POS;
        if (curPos.x > MAX_POS) curPos.x = MAX_POS;
        mCamera.transform.localPosition = curPos;
    }
    void AssignCamera(float delta)
    {
        Vector3 pos = mCamera.transform.localPosition;
        pos.x = delta;
        if (pos.x < MIN_POS) pos.x = MIN_POS;
        if (pos.x > MAX_POS) pos.x = MAX_POS;
        curPos.x = pos.x;
        mCamera.transform.localPosition = pos;
    }
}
 |