FindTransform() public static method

public static FindTransform ( GameObject parentObj, string objName ) : Transform
parentObj GameObject
objName string
return Transform
示例#1
0
    public void Initialize(GameObject go)
    {
        rightElbow = UnityUtils.FindTransform(go, "R_Elbow");
        leftElbow  = UnityUtils.FindTransform(go, "L_Elbow");
        rightArm   = UnityUtils.FindTransform(go, "R_Arm");
        leftArm    = UnityUtils.FindTransform(go, "L_Arm");
        rightKnee  = UnityUtils.FindTransform(go, "R_Knee");
        leftKnee   = UnityUtils.FindTransform(go, "L_Knee");
        rightHip   = UnityUtils.FindTransform(go, "R_Hip");
        leftHip    = UnityUtils.FindTransform(go, "L_Hip");
        spine      = UnityUtils.FindTransform(go, "Spine_1");
        root       = UnityUtils.FindTransform(go, "Root");

        initialRotations = new Quaternion[(int)NiteWrapper.SkeletonJoint.END];
        initialRotations[(int)NiteWrapper.SkeletonJoint.LEFT_ELBOW]     = leftElbow.rotation;
        initialRotations[(int)NiteWrapper.SkeletonJoint.RIGHT_ELBOW]    = rightElbow.rotation;
        initialRotations[(int)NiteWrapper.SkeletonJoint.LEFT_SHOULDER]  = leftArm.rotation;
        initialRotations[(int)NiteWrapper.SkeletonJoint.RIGHT_SHOULDER] = rightArm.rotation;
        initialRotations[(int)NiteWrapper.SkeletonJoint.RIGHT_KNEE]     = rightKnee.rotation;
        initialRotations[(int)NiteWrapper.SkeletonJoint.LEFT_KNEE]      = leftKnee.rotation;
        initialRotations[(int)NiteWrapper.SkeletonJoint.RIGHT_HIP]      = rightHip.rotation;
        initialRotations[(int)NiteWrapper.SkeletonJoint.LEFT_HIP]       = leftHip.rotation;
        initialRotations[(int)NiteWrapper.SkeletonJoint.TORSO_CENTER]   = spine.rotation;
        initialRoot = root.rotation;

        RotateToCalibrationPose();
    }
示例#2
0
    // Use this for initialization
    void Start()
    {
        foodsprite.Add(1, "Texture/bean_polygon3_1");
        foodsprite.Add(2, "Texture/bean_polygon3_2");
        foodsprite.Add(3, "Texture/bean_polygon3_3");
        foodsprite.Add(4, "Texture/bean_polygon3_4");
        foodsprite.Add(5, "Texture/bean_polygon3_5");
        foodsprite.Add(6, "Texture/bean_polygon3_6");
        foodsprite.Add(7, "Texture/bean_polygon4_1");
        foodsprite.Add(8, "Texture/bean_polygon4_2");
        foodsprite.Add(9, "Texture/bean_polygon4_3");
        foodsprite.Add(10, "Texture/bean_polygon4_4");
        foodsprite.Add(11, "Texture/bean_polygon4_5");
        foodsprite.Add(12, "Texture/bean_polygon4_6");

        playersprite.Add(1, "Texture/bean_polygon5_1");
        playersprite.Add(2, "Texture/bean_polygon5_2");
        playersprite.Add(3, "Texture/bean_polygon5_3");
        playersprite.Add(4, "Texture/bean_polygon5_4");
        playersprite.Add(5, "Texture/bean_polygon5_5");
        playersprite.Add(6, "Texture/bean_polygon5_6");

        xpos = transform.Find("UI/Xpos").GetComponent <Text>();
        ypos = transform.Find("UI/Ypos").GetComponent <Text>();

        scene = UnityUtils.FindTransform("Scene/World");

        Network.Register <S2CEnterRoom>(v => {
            var e = new Entity();
            entitas.Add(v.id, e);
            local = e;
        });

        Network.Register <S2CEnterView>(v => {
            var e = new Entity();
            if (!entitas.ContainsKey(v.id))
            {
                entitas.Add(v.id, e);
                Debug.LogFormat("Entity  id {0} enter view", v.id);
            }
        });

        Network.Register <S2CLeaveView>(v =>
        {
            Entity e;
            if (entitas.TryGetValue(v.id, out e))
            {
                if (e.Mover)
                {
                    e.NameText.transform.SetParent(null);
                }

                //Debug.LogFormat("Entity id {0} leave view", v.id);
                Destroy(e.Go);
                entitas.Remove(v.id);
            }
        });

        Network.Register <S2CDead>(v =>
        {
            Entity e;
            if (entitas.TryGetValue(v.id, out e))
            {
                e.NameText.transform.SetParent(null);
                Debug.LogFormat("Entity id {0} dead", v.id);
                if (v.id == UserData.uid)
                {
                    SceneManager.LoadScene("Login");
                    return;
                }
                Destroy(e.Go);
                entitas.Remove(v.id);
            }
        });

        Network.Register <Mover>(v => {
            Entity e;
            if (entitas.TryGetValue(v.id, out e))
            {
                e.Mover = true;
            }
        });

        Network.Register <Food>(v => {
            Entity e;
            if (entitas.TryGetValue(v.id, out e))
            {
                e.Food = true;
            }
        });

        Network.Register <BaseData>(v => {
            Entity e;
            if (entitas.TryGetValue(v.id, out e))
            {
                e.BaseData = v.data;

                GameObject go = Instantiate(Resources.Load <GameObject>("Prefab/Player"));
                var spr       = go.GetComponent <SpriteRenderer>();
                string source;
                if (e.Mover)
                {
                    if (!playersprite.TryGetValue(e.BaseData.spriteid, out source))
                    {
                        source = "Texture/bean_polygon5_1";
                    }
                }
                else if (e.Food)
                {
                    if (!foodsprite.TryGetValue(e.BaseData.spriteid, out source))
                    {
                        source = "Texture/bean_polygon3_1";
                    }
                }
                else
                {
                    return;
                }

                spr.sprite            = UnityUtils.LoadSprite(source);
                spr.sortingLayerName  = "Player";
                go.transform.position = new Vector3(0, 0, 0);
                go.transform.SetParent(scene);
                //go.AddComponent<LineRenderer>();
                e.Go = go;

                if (e.Mover)
                {
                    e.NameText = Instantiate(Resources.Load <GameObject>("Prefab/TextName"));
                    e.NameText.transform.SetParent(transform);
                    var text       = e.NameText.GetComponent <Text>();
                    text.text      = e.BaseData.name;
                    text.color     = UnityEngine.Color.green;
                    text.alignment = TextAnchor.UpperCenter;
                    text.fontStyle = FontStyle.Bold;
                    text.fontSize  = 21;
                }
            }
        });

        Network.Register <Position>(v => {
            Entity e;
            if (entitas.TryGetValue(v.id, out e))
            {
                e.Position = v.data;
                if (null != e.Go)
                {
                    e.Go.transform.position = new Vector3(e.Position.x, e.Position.y, e.Go.transform.position.z);
                    Debug.LogFormat("Entity id {0} Position {1} {2}", v.id, e.Position.x, e.Position.y);
                }
            }
        });

        Network.Register <Direction>(v => {
            Entity e;
            if (entitas.TryGetValue(v.id, out e))
            {
                e.Direction = v.data;
            }
        });

        Network.Register <Speed>(v => {
            Entity e;
            if (entitas.TryGetValue(v.id, out e))
            {
                e.Speed = v.data;
            }
        });

        Network.Register <Color>(v => {
            Entity e;
            if (entitas.TryGetValue(v.id, out e))
            {
                e.Color = v.data;
            }
        });

        Network.Register <Radius>(v => {
            Entity e;
            if (entitas.TryGetValue(v.id, out e))
            {
                e.Radius        = v.data;
                var rect        = e.Go.GetComponent <RectTransform>();
                rect.localScale = new Vector3(2 * e.Radius.value / 0.3f, 2 * e.Radius.value / 0.3f, 1);
            }
        });

        Network.Send(UserData.GameSeverID, new C2SEnterRoom {
            username = UserData.username
        });
    }
示例#3
0
    // Use this for initialization
    void Start()
    {
        foodsprite.Add(1, "Texture/bean_polygon3_1");
        foodsprite.Add(2, "Texture/bean_polygon3_2");
        foodsprite.Add(3, "Texture/bean_polygon3_3");
        foodsprite.Add(4, "Texture/bean_polygon3_4");
        foodsprite.Add(5, "Texture/bean_polygon3_5");
        foodsprite.Add(6, "Texture/bean_polygon3_6");
        foodsprite.Add(7, "Texture/bean_polygon4_1");
        foodsprite.Add(8, "Texture/bean_polygon4_2");
        foodsprite.Add(9, "Texture/bean_polygon4_3");
        foodsprite.Add(10, "Texture/bean_polygon4_4");
        foodsprite.Add(11, "Texture/bean_polygon4_5");
        foodsprite.Add(12, "Texture/bean_polygon4_6");

        playersprite.Add(1, "Texture/bean_polygon5_1");
        playersprite.Add(2, "Texture/bean_polygon5_2");
        playersprite.Add(3, "Texture/bean_polygon5_3");
        playersprite.Add(4, "Texture/bean_polygon5_4");
        playersprite.Add(5, "Texture/bean_polygon5_5");
        playersprite.Add(6, "Texture/bean_polygon5_6");

        xpos      = transform.Find("UI/Xpos").GetComponent <Text>();
        ypos      = transform.Find("UI/Ypos").GetComponent <Text>();
        countDown = transform.Find("UI/CountDown").GetComponent <Text>();

        scene = UnityUtils.FindTransform("Scene/World");

        playerPrefab = Resources.Load <GameObject>("Prefab/Player");
        namePrefab   = Resources.Load <GameObject>("Prefab/TextName");

        Network.Register <S2CEnterRoom>(v => {
            var e = new Entity();
            entitas.Add(v.id, e);
            local = e;
        });

        Network.Register <S2CEnterView>(v => {
            var e = new Entity();
            if (!entitas.ContainsKey(v.id))
            {
                entitas.Add(v.id, e);
                Debug.LogFormat("Entity  id {0} enter view", v.id);
            }
        });

        Network.Register <S2CLeaveView>(v =>
        {
            Entity e;
            if (entitas.TryGetValue(v.id, out e))
            {
                var text  = e.NameText.GetComponent <Text>();
                text.text = "DEAD";
                e.NameText.transform.SetParent(null);
                e.Go.transform.SetParent(null);
                Destroy(e.NameText);
                Destroy(e.Go);
                e.NameText = null;
                e.Go       = null;
                if (entitas.Remove(v.id))
                {
                    Debug.LogFormat("Entity Destroy {0} {1} {2}", v.id, e.Position.x, e.Position.y);
                }
            }
        });

        Network.Register <S2CDead>(v =>
        {
            Entity e;
            if (entitas.TryGetValue(v.id, out e))
            {
                Debug.LogFormat("You dead id {0} dead", v.id);
                if (v.id == UserData.uid)
                {
                    SceneManager.LoadScene("Login");
                    return;
                }
            }
        });

        Network.Register <Mover>(v => {
            Entity e;
            if (entitas.TryGetValue(v.id, out e))
            {
                e.Mover = true;
            }
        });

        Network.Register <Food>(v => {
            Entity e;
            if (entitas.TryGetValue(v.id, out e))
            {
                e.Food = true;
            }
        });

        Network.Register <BaseData>(v => {
            Entity e;
            if (entitas.TryGetValue(v.id, out e))
            {
                e.BaseData = v.data;

                GameObject go = Instantiate(
                    playerPrefab,
                    new Vector3(e.Position.x, e.Position.y, 0),
                    Quaternion.identity);
                var spr = go.GetComponent <SpriteRenderer>();
                string source;
                if (e.Mover)
                {
                    if (!playersprite.TryGetValue(e.BaseData.spriteid, out source))
                    {
                        source = "Texture/bean_polygon5_1";
                    }
                }
                else if (e.Food)
                {
                    if (!foodsprite.TryGetValue(e.BaseData.spriteid, out source))
                    {
                        source = "Texture/bean_polygon3_1";
                    }
                }
                else
                {
                    return;
                }

                spr.sprite            = UnityUtils.LoadSprite(source);
                spr.sortingLayerName  = "Player";
                go.transform.position = new Vector3(e.Position.x, e.Position.y, 0);
                go.transform.SetParent(scene);
                //go.AddComponent<LineRenderer>();
                e.Go       = go;
                e.NameText = Instantiate(namePrefab);
                e.NameText.transform.SetParent(transform);
                var text       = e.NameText.GetComponent <Text>();
                text.text      = e.Mover ? e.BaseData.name : e.BaseData.id.ToString();
                text.color     = UnityEngine.Color.green;
                text.alignment = TextAnchor.UpperCenter;
                text.fontStyle = FontStyle.Bold;
                text.fontSize  = 21;
            }
        });

        Network.Register <Position>(v => {
            Entity e;
            if (entitas.TryGetValue(v.id, out e))
            {
                e.Position = v.data;
            }
        });

        Network.Register <Direction>(v => {
            Entity e;
            if (entitas.TryGetValue(v.id, out e))
            {
                e.Direction = v.data;
            }
        });

        Network.Register <Speed>(v => {
            Entity e;
            if (entitas.TryGetValue(v.id, out e))
            {
                e.Speed = v.data;
            }
        });

        Network.Register <Color>(v => {
            Entity e;
            if (entitas.TryGetValue(v.id, out e))
            {
                e.Color = v.data;
            }
        });

        Network.Register <Radius>(v => {
            Entity e;
            if (entitas.TryGetValue(v.id, out e))
            {
                e.Radius = v.data;
            }
        });

        Network.Register <S2CGameOver>(v => {
            gameOver = true;
            MessageBox.Show(string.Format("Game Over, Score : {0}", v.score), (res) => {
                SceneManager.LoadScene("Login");
            });
        });

        Network.Send(UserData.GameSeverID, new C2SEnterRoom {
            username = UserData.username
        });

        InvokeRepeating("CountDown", 1f, 1.0f);
    }
示例#4
0
    // Use this for initialization
    void Start()
    {
        foodsprite.Add(1, "Texture/bean_polygon3_1");
        foodsprite.Add(2, "Texture/bean_polygon3_2");
        foodsprite.Add(3, "Texture/bean_polygon3_3");
        foodsprite.Add(4, "Texture/bean_polygon3_4");
        foodsprite.Add(5, "Texture/bean_polygon3_5");
        foodsprite.Add(6, "Texture/bean_polygon3_6");
        foodsprite.Add(7, "Texture/bean_polygon4_1");
        foodsprite.Add(8, "Texture/bean_polygon4_2");
        foodsprite.Add(9, "Texture/bean_polygon4_3");
        foodsprite.Add(10, "Texture/bean_polygon4_4");
        foodsprite.Add(11, "Texture/bean_polygon4_5");
        foodsprite.Add(12, "Texture/bean_polygon4_6");

        playersprite.Add(1, "Texture/bean_polygon5_1");
        playersprite.Add(2, "Texture/bean_polygon5_2");
        playersprite.Add(3, "Texture/bean_polygon5_3");
        playersprite.Add(4, "Texture/bean_polygon5_4");
        playersprite.Add(5, "Texture/bean_polygon5_5");
        playersprite.Add(6, "Texture/bean_polygon5_6");

        xpos      = transform.Find("UI/Xpos").GetComponent <Text>();
        ypos      = transform.Find("UI/Ypos").GetComponent <Text>();
        countDown = transform.Find("UI/CountDown").GetComponent <Text>();

        scene = UnityUtils.FindTransform("Scene/World");

        playerPrefab = Resources.Load <GameObject>("Prefab/Player");
        namePrefab   = Resources.Load <GameObject>("Prefab/TextName");



        Network.Register <S2CEnterRoom>(v => {
            uid           = v.id;
            UserData.time = v.time;
            now           = Millseconds();
        });

        Network.Register <S2CEnterView>(v => {
            var e = new Entity();
            if (!entitas.ContainsKey(v.id))
            {
                e.id       = v.id;
                e.radius   = v.radius;
                e.speed    = v.speed;
                e.spriteid = v.spriteid;
                e.pos      = new Vector2 {
                    x = v.x, y = v.y
                };
                e.dir         = v.dir;
                e.name        = v.name;
                e.movetime    = v.movetime;
                bool isplayer = IsPlayer(e.id);
                GameObject go = Instantiate(playerPrefab, new Vector3(e.pos.x, e.pos.y, 0), Quaternion.identity);
                var spr       = go.GetComponent <SpriteRenderer>();
                string source;
                if (isplayer)
                {
                    if (!playersprite.TryGetValue((int)e.spriteid, out source))
                    {
                        source = "Texture/bean_polygon5_1";
                    }
                }
                else
                {
                    if (!foodsprite.TryGetValue((int)e.spriteid, out source))
                    {
                        source = "Texture/bean_polygon3_1";
                    }
                }

                spr.sprite            = UnityUtils.LoadSprite(source);
                spr.sortingLayerName  = "Player";
                go.transform.position = new Vector3(e.pos.x, e.pos.y, 0);
                go.transform.SetParent(scene);
                //go.AddComponent<LineRenderer>();
                e.Go       = go;
                e.NameText = Instantiate(namePrefab);
                e.NameText.transform.SetParent(transform);
                var text       = e.NameText.GetComponent <Text>();
                text.text      = isplayer ? e.name : e.id.ToString();
                text.color     = UnityEngine.Color.green;
                text.alignment = TextAnchor.UpperCenter;
                text.fontStyle = FontStyle.Bold;
                text.fontSize  = 21;
                entitas.Add(v.id, e);
                Debug.LogFormat("Entity  id {0} enter view", v.id);

                if (v.id == uid)
                {
                    local = e;
                }
            }
        });

        Network.Register <S2CLeaveView>(v =>
        {
            Entity e;
            if (entitas.TryGetValue(v.id, out e))
            {
                var text  = e.NameText.GetComponent <Text>();
                text.text = "DEAD";
                e.NameText.transform.SetParent(null);
                e.Go.transform.SetParent(null);
                Destroy(e.NameText);
                Destroy(e.Go);
                e.NameText = null;
                e.Go       = null;
                if (entitas.Remove(v.id))
                {
                    Debug.LogFormat("Entity Destroy {0} {1} {2}", v.id, e.pos.x, e.pos.y);
                }
            }
        });

        Network.Register <S2CMove>(v => {
            Entity e;
            if (entitas.TryGetValue(v.id, out e))
            {
                //var delta = (UserData.time - e.movetime) / 1000.0f;
                //var deltalen = e.dir.normalized * e.speed * delta;
                //Vector2 nowPos = e.pos + deltalen;
                //Debug.LogFormat("S2CMove {0} {1} {2} {3}", UserData.time, e.movetime, nowPos.x, nowPos.y);
                e.pos.x    = v.x;
                e.pos.y    = v.y;
                e.dir.x    = v.dirx;
                e.dir.y    = v.diry;
                e.movetime = v.movetime;
            }
        });

        Network.Register <S2CUpdateRadius>(v =>
        {
            Entity e;
            if (entitas.TryGetValue(v.id, out e))
            {
                e.radius = v.radius;
            }
        });

        Network.Register <S2CDead>(v =>
        {
            Entity e;
            if (entitas.TryGetValue(v.id, out e))
            {
                Debug.LogFormat("You dead id {0} dead", v.id);
                if (v.id == UserData.uid)
                {
                    SceneManager.LoadScene("Login");
                    return;
                }
            }
        });

        Network.Register <S2CGameOver>(v => {
            gameOver = true;
            MessageBox.Show(string.Format("Game Over, Score : {0}", v.score), (res) => {
                SceneManager.LoadScene("Login");
            });
        });

        Network.Send(UserData.GameSeverID, new C2SEnterRoom {
            name = UserData.username
        });

        InvokeRepeating("CountDown", 1f, 1.0f);
    }