public void AddBall(LevelData.BallData data)
        {
            string name = data.Type.ToString();
            GameObject o = Instantiate((GameObject)Resources.Load(name)) as GameObject;

            o.transform.SetParent(m_CustomBallRoot.transform);
            o.transform.localRotation = Quaternion.identity;
            o.transform.localPosition = new Vector3(data.Position.x, -2.3f, data.Position.z);

            Texture2D tex = Resources.LoadAssetAtPath<Texture2D>("Assets/Images/EditorTextures/" + name + ".png");
            TouchObject to = new TouchObject() { transform = o.transform, id = data.ID, rect = data.pRect, texture = tex, type = data.Type };
            m_Balls.Add(to.id , to);
        }
Beispiel #2
0
        void Awake()
        {
            if (!EditorApplication.currentScene.Contains("PoolGame"))
            {
                return;
            }
            GetLevelDataIndex();
            m_CustomBallRoot = GameObject.Find("8Ball/OtherObjects").transform;
            Transform trans = GameObject.Find("WhiteBall").transform;
            Texture2D tex   = Resources.LoadAssetAtPath <Texture2D>("Assets/Images/EditorTextures/CUEBALL.png");

            m_PocketTexture = Resources.LoadAssetAtPath <Texture2D>("Assets/Images/EditorTextures/Pocket.png");
            m_CueBall       = new TouchObject()
            {
                transform = trans, texture = tex, id = 0, type = BallType.WHITE
            };
            HideStandardBalls();

            string ss = "Table/Colliders/pocket_";

            m_Pockets[0] = new Pocket(m_LeftTop, m_PocketTexture, GameObject.Find(ss + "TopLeft"), PocketIndexes.TopLeft);
            m_Pockets[1] = new Pocket(m_Top, m_PocketTexture, GameObject.Find(ss + "TopCenter"), PocketIndexes.TopCenter);
            m_Pockets[2] = new Pocket(m_RightTop, m_PocketTexture, GameObject.Find(ss + "TopRight"), PocketIndexes.TopRight);
            m_Pockets[3] = new Pocket(m_LeftBottom, m_PocketTexture, GameObject.Find(ss + "BottomLeft"), PocketIndexes.BottomLeft);
            m_Pockets[4] = new Pocket(m_Bottom, m_PocketTexture, GameObject.Find(ss + "BottomCenter"), PocketIndexes.BottomCenter);
            m_Pockets[5] = new Pocket(m_RightBottom, m_PocketTexture, GameObject.Find(ss + "BottomRight"), PocketIndexes.BottomRight);

            GameObject o1 = GameObject.FindObjectOfType <WhiteBall>().gameObject;
            Constraint c  = o1.GetComponent <Constraint>();

            m_R = o1.GetComponent <SphereCollider>().radius *o1.transform.lossyScale.x;

            TableMin                = new Vector2(c.min.x + m_R, c.min.z + m_R);
            TableMax                = new Vector2(c.max.x - m_R, c.max.z - m_R);
            XSize                   = TableMax.x - TableMin.x;
            YSize                   = TableMax.y - TableMin.y;
            m_Aspect                = YSize / XSize;
            m_GridSize              = c.GetComponent <SphereCollider>().radius *c.transform.localScale.x - ConstantData.BallRadiusAdjustment;
            AreaWidth               = 953;//constant value
            AreaHeight              = AreaWidth * m_Aspect;
            m_xRadio                = AreaWidth / XSize;
            m_yRadio                = AreaHeight / YSize;
            m_GridSize              = m_GridSize * AreaWidth / XSize;
            m_BackgroundRect.width  = AreaWidth + 2 * m_GridSize;
            m_BackgroundRect.height = AreaHeight + 2 * m_GridSize;
            //m_BackImage = Resources.LoadAssetAtPath<Texture2D>("Assets/Images/Table/bian.png");
            SyncData();
            GetBallObjectsRect();
        }
Beispiel #3
0
        public void AddBall(LevelData.BallData data)
        {
            string     name = data.Type.ToString();
            GameObject o    = Instantiate((GameObject)Resources.Load(name)) as GameObject;

            o.transform.SetParent(m_CustomBallRoot.transform);
            o.transform.localRotation = Quaternion.identity;
            o.transform.localPosition = new Vector3(data.Position.x, -2.3f, data.Position.z);

            Texture2D   tex = Resources.LoadAssetAtPath <Texture2D>("Assets/Images/EditorTextures/" + name + ".png");
            TouchObject to  = new TouchObject()
            {
                transform = o.transform, id = data.ID, rect = data.pRect, texture = tex, type = data.Type
            };

            m_Balls.Add(to.id, to);
        }
        public void AddBall(object t)
        {
            BallType type = (BallType)t;
            string name = type.ToString();

            GameObject o = Instantiate((GameObject)Resources.Load(name)) as GameObject;

            o.transform.SetParent(m_CustomBallRoot.transform);
            o.transform.localRotation = Quaternion.identity;
            //o.transform.localPosition = new Vector3(-7.6f, -2.3f, 0);

            Texture2D tex = Resources.LoadAssetAtPath<Texture2D>("Assets/Images/EditorTextures/" + name + ".png");
            Rect rect = new Rect(backgroundHitPoint.x, backgroundHitPoint.y, m_GridSize * 2, m_GridSize * 2);
            TouchObject to = new TouchObject() { transform = o.transform, id = o.GetInstanceID(), texture = tex, type = type, rect = rect};
            m_Balls.Add(to.id, to);

            //GetBallObjectsRect();
        }
Beispiel #5
0
        public void AddBall(object t)
        {
            BallType type = (BallType)t;
            string   name = type.ToString();

            GameObject o = Instantiate((GameObject)Resources.Load(name)) as GameObject;

            o.transform.SetParent(m_CustomBallRoot.transform);
            o.transform.localRotation = Quaternion.identity;
            //o.transform.localPosition = new Vector3(-7.6f, -2.3f, 0);

            Texture2D   tex  = Resources.LoadAssetAtPath <Texture2D>("Assets/Images/EditorTextures/" + name + ".png");
            Rect        rect = new Rect(backgroundHitPoint.x, backgroundHitPoint.y, m_GridSize * 2, m_GridSize * 2);
            TouchObject to   = new TouchObject()
            {
                transform = o.transform, id = o.GetInstanceID(), texture = tex, type = type, rect = rect
            };

            m_Balls.Add(to.id, to);

            //GetBallObjectsRect();
        }
        void Awake()
        {
            if (!EditorApplication.currentScene.Contains("PoolGame"))
                return;
            GetLevelDataIndex();
            m_CustomBallRoot = GameObject.Find("8Ball/OtherObjects").transform;
            Transform trans = GameObject.Find("WhiteBall").transform;
            Texture2D tex = Resources.LoadAssetAtPath<Texture2D>("Assets/Images/EditorTextures/CUEBALL.png");
            m_PocketTexture = Resources.LoadAssetAtPath<Texture2D>("Assets/Images/EditorTextures/Pocket.png");
            m_CueBall = new TouchObject() { transform = trans, texture = tex, id = 0, type = BallType.WHITE };
            HideStandardBalls();

            string ss = "Table/Colliders/pocket_";
            m_Pockets[0] = new Pocket(m_LeftTop, m_PocketTexture, GameObject.Find(ss + "TopLeft"), PocketIndexes.TopLeft);
            m_Pockets[1] = new Pocket(m_Top, m_PocketTexture, GameObject.Find(ss + "TopCenter"), PocketIndexes.TopCenter);
            m_Pockets[2] = new Pocket(m_RightTop, m_PocketTexture, GameObject.Find(ss + "TopRight"), PocketIndexes.TopRight);
            m_Pockets[3] = new Pocket(m_LeftBottom, m_PocketTexture, GameObject.Find(ss + "BottomLeft"), PocketIndexes.BottomLeft);
            m_Pockets[4] = new Pocket(m_Bottom, m_PocketTexture, GameObject.Find(ss + "BottomCenter"), PocketIndexes.BottomCenter);
            m_Pockets[5] = new Pocket(m_RightBottom, m_PocketTexture, GameObject.Find(ss + "BottomRight"), PocketIndexes.BottomRight);

            GameObject o1 = GameObject.FindObjectOfType<WhiteBall>().gameObject;
            Constraint c = o1.GetComponent<Constraint>();
            m_R = o1.GetComponent<SphereCollider>().radius * o1.transform.lossyScale.x;

            TableMin = new Vector2(c.min.x + m_R, c.min.z + m_R);
            TableMax = new Vector2(c.max.x - m_R, c.max.z - m_R);
            XSize = TableMax.x - TableMin.x;
            YSize = TableMax.y - TableMin.y;
            m_Aspect = YSize / XSize;
            m_GridSize = c.GetComponent<SphereCollider>().radius * c.transform.localScale.x - ConstantData.BallRadiusAdjustment;
            AreaWidth = 953;//constant value
            AreaHeight = AreaWidth * m_Aspect;
            m_xRadio = AreaWidth / XSize;
            m_yRadio = AreaHeight / YSize;
            m_GridSize = m_GridSize * AreaWidth / XSize;
            m_BackgroundRect.width = AreaWidth + 2 * m_GridSize;
            m_BackgroundRect.height = AreaHeight + 2 * m_GridSize;
            //m_BackImage = Resources.LoadAssetAtPath<Texture2D>("Assets/Images/Table/bian.png");
            SyncData();
            GetBallObjectsRect();
        }