Example #1
0
    // Update is called once per frame
    public void Refresh(string sign)
    {
        if (sign == "+")
        {
            currentworld++;
        }
        else
        {
            currentworld--;
        }
        foreach (GameObject Go in frames)
        {
            Go.GetComponent <CallLevel> ().ManageStars();
            Go.GetComponent <CallLevel> ().world = currentworld;
        }

        if (currentworld > 1)
        {
            prev.GetComponent <Button> ().interactable = true;
        }
        else
        {
            prev.GetComponent <Button> ().interactable = false;
        }
        if (currentworld < 9)
        {
            next.GetComponent <Button> ().interactable = true;
        }
        else
        {
            next.GetComponent <Button> ().interactable = false;
        }

        worldtext.text = GameObject.Find("GameManager").gameObject.GetComponent <LevelLoader> ().worldsnames [currentworld - 1];
    }
Example #2
0
        public override void Init(string objName)
        {
            //attach gameobject in scene
            base.Init(objName);

            _image = Go.GetComponent <Image>();
        }
Example #3
0
        public ButtonObject(string buttonImageFileName, string text, Action onClick)
        {
            Go = Resources.Load(Settings.PREFAB_PATH + "Button") as GameObject;
            // Go.SetActive(false);
            Go = GameObject.Instantiate <GameObject>(Go);

            _image = Go.GetComponent <Image>();

            Sprite sprite = Resources.Load <Sprite>(Settings.UI_IMAGE_PATH + buttonImageFileName);

            if (_image && sprite)
            {
                _image.sprite = sprite;
            }
            else
            {
                Debug.Log("Do not find image file");
            }

            _text      = Go.GetComponentInChildren <Text>();
            _text.text = text;

            _button = Go.GetComponent <Button>();
            if (_button)
            {
                _button.onClick.AddListener(new UnityEngine.Events.UnityAction(onClick));
            }
        }
Example #4
0
 protected override void OnInit()
 {
     base.OnInit();
     Template_button = Go.GetComponent <UnityEngine.UI.Button>();
     Text_go         = Go.transform.Find("Text").gameObject;
     Text_text       = Text_go.GetComponent <UnityEngine.UI.Text>();
     Template_button.onClick.AddListener(OnClick);
 }
Example #5
0
    public void Exit()
    {
        foreach (GameObject Go in Buttons)
        {
            Go.GetComponent <Toggle>().isOn = false;
        }

        UseGyro = false;
    }
    private void Handle_Completed(AssetOperationHandle obj)
    {
        if (_handle.AssetObject == null)
        {
            return;
        }

        Go = _handle.InstantiateObject;

        // 设置父类
        GameObject uiDesktop = UIManager.Instance.UIDesktop;

        Go.transform.SetParent(uiDesktop.transform, false);

        // 获取组件
        _manifest = Go.GetComponent <UIManifest>();
        if (_manifest == null)
        {
            GameLogger.Error($"Not found {nameof(UIManifest)} in window {WindowType}");
            return;
        }

        // 获取组件
        _canvas = Go.GetComponent <Canvas>();
        if (_canvas == null)
        {
            GameLogger.Error($"Not found {nameof(Canvas)} in window {WindowType}");
            return;
        }
        _canvas.overrideSorting = true;

        // 获取组件
        _raycaster = Go.GetComponent <GraphicRaycaster>();
        if (_raycaster == null)
        {
            GameLogger.Error($"Not found {nameof(GraphicRaycaster)} in window {WindowType}");
            return;
        }

        // 获取组件
        _childCanvas    = Go.GetComponentsInChildren <Canvas>(true);
        _childRaycaster = Go.GetComponentsInChildren <GraphicRaycaster>(true);

        // 虚函数
        if (IsPrepare == false)
        {
            IsPrepare = true;
            OnCreate();
        }

        // 最后设置是否激活
        Go.SetActive(IsOpen);

        // 通知UI管理器
        _userCallback?.Invoke(this);
    }
Example #7
0
        public T Get <T>() where T : Component
        {
            if (Go == null)
            {
                Debug.LogError(GetType() + "/Get()/ current gameObject is null:" + Go.name);
                return(null);
            }

            return(Go.GetComponent <T>());
        }
Example #8
0
    public T Get <T>() where T : Component
    {
        if (Go != null)
        {
            return(Go.GetComponent <T>());
        }

        Debug.LogError("當前GameObject為空");
        return(null);
    }
Example #9
0
        public T Get <T>() where T : Component
        {
            if (Go != null)
            {
                return(Go.GetComponent <T>());
            }

            Debug.LogError("当前gameobject为空");
            return(null);
        }
Example #10
0
 private bool doesGridHoldAPipe(float x, float y)
 {
     foreach (GameObject Go in pipeGrid)
     {
         BgTile bgt = Go.GetComponent <BgTile>();
         if (bgt.transform.position.x == x && bgt.transform.position.y == y)
         {
             return(bgt.pipeOnBg != null);
         }
     }
     return(false);
 }
        /// <summary>
        /// Shoots the alt weapon for the ship in use
        /// </summary>
        protected virtual IEnumerator ShootAltWeapon(Vector2 Direction, float Spd = 10, int?ShotFrom = null)
        {
            CanShootAlt = false;

            GameObject Go;

            if (!IsEm)
            {
                Go = GetAltWeaponObj();
            }
            else
            {
                Go = GetComponent <Enemies>().EmWeapons.GetOrbVariant();
            }

            if (Go)
            {
                Go.transform.position = AltPointToShootFrom().transform.position;
                Go.SetActive(true);

                if (Go.GetComponent <MissileScript>())
                {
                    Go.GetComponent <MissileScript>().ShouldFindTarget = true;
                }
                else
                {
                    Go.GetComponent <Rigidbody2D>().velocity += Direction * Spd;
                }


                Go.GetComponent <Damage>().DMG = (int)Ship.AltWeapon.Damage[(int)GM.ActiveStage];


                // Sets who shot the bullet if it has a value
                if (ShotFrom != null)
                {
                    Go.GetComponent <Damage>().SetPlayerShotFrom((int)ShotFrom);
                }

                // Wait for delay time before lettings the player shoot again
                yield return(new WaitForSeconds(Ship.AltWeapon.Delay));

                CanShootAlt = true;
            }
            else
            {
                yield return(new WaitForSeconds(0));

                CanShootAlt = true;
            }

            PlayerStats.altShotsFired++;
        }
Example #12
0
    private void handleClick(Vector3 worldPos, RaycastHit2D hitData)
    {
        bool isBackgroundTile = hitData && hitData.collider.GetComponent <BgTile>() != null;

        if (isBackgroundTile)
        {
            // player clicks on bar to select a pipe
            if (hitData.collider.GetComponent <BgTile>().IsPipeBar)
            {
                SelectedPipe = pipeBarContent[hitData.collider.GetComponent <BgTile>().pipeBarID];
            }
            // player has clicked on the grid
            else
            {
                // the player has a selected pipe that he wants to place
                if (SelectedPipe != null)
                {
                    if (isPipePlacementAllowed(SelectedPipe, hitData.collider.gameObject))
                    {
                        if (isPipeNextToLatestPipe(hitData.collider.gameObject))
                        {
                            // placing pipe
                            GameObject TempGo = Instantiate(SelectedPipe, hitData.transform.position, Quaternion.identity);
                            // registering pipe on tile
                            hitData.collider.gameObject.GetComponent <BgTile>().pipeOnBg = TempGo;
                            // adding to pipelist for waterflow
                            pipeList.Add(TempGo.GetComponent <Pipe>());
                            // the player now has to select a new pipe
                            SelectedPipe = null;

                            // check if game won
                            foreach (GameObject Go in pipeGrid)
                            {
                                BgTile bgt = Go.GetComponent <BgTile>();
                                if (bgt.transform.position.x == endPipe.transform.position.x - 1 && bgt.transform.position.y == endPipe.transform.position.y)
                                {
                                    if (bgt.pipeOnBg != null)
                                    {
                                        if (bgt.pipeOnBg.GetComponent <Pipe>().pipeType == Pipe.PipeType.HorizontalPipe || bgt.pipeOnBg.GetComponent <Pipe>().pipeType == Pipe.PipeType.LeftUpPipe ||  bgt.pipeOnBg.GetComponent <Pipe>().pipeType == Pipe.PipeType.LeftDownPipe)
                                        {
                                            GameWon();
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
Example #13
0
    public PlayerHud(GameObject go, U3DSceneObject player) : base(go)
    {
        U3DSceneObject = player;

        #region AutoMaticAssign
        m_Hp_go     = Go.transform.Find("m_Hp").gameObject;
        m_Hp_slider = m_Hp_go.GetComponent <Slider>();
        #endregion
        _maxHp = U3DSceneObject.SceneObject.AttributeManager[AttributeType.Maxhp].ToInt();
        _curHp = U3DSceneObject.SceneObject.AttributeManager[AttributeType.Hp].ToInt();
        UpdateSlider();
        U3DSceneObject.SceneObject.TransformComp.EventGroup.ListenEvent((int)TransformComponent.Event.OnPositionChange, OnAttributeChange);
        rt = Go.GetComponent <RectTransform>();
    }
Example #14
0
        public override void Init(ObjectInfo info)
        {
            base.Init(info);

            _info = (ImageInfo)info;

            //TODO: create by prefab
            //TODO: 同一加载管理Prefab
            if (_info.PrefabName != "")
            {
                Go = Resources.Load <GameObject>(_info.PrefabName);
                if (Go == null)
                {
                    Go     = new GameObject(info.ObjName);
                    _image = Go.AddComponent <Image>();
                }
                else
                {
                    Go     = GameObject.Instantiate(Go);
                    _image = Go.GetComponent <Image>();
                }
            }
            else
            {
                Go     = new GameObject(info.ObjName);
                _image = Go.AddComponent <Image>();
            }

            //set gameobject name
            Go.name = _info.ObjName;
            //create image
            Sprite i = Resources.Load <Sprite>(_info.Path + _info.Name);

            if (i == null)
            {
                Debug.LogFormat("Cannot load image file:{0}", _info.Path + _info.Name);
            }
            _image.sprite = i;
            //set root
            GameObject parent = GameObject.Find(_info.Root);

            if (parent)
            {
                Go.transform.SetParent(parent.transform, false);
            }
            _image.SetNativeSize();

            Go.SetActive(false);
        }
Example #15
0
    void ApplyRules()
    {
        GameObject[] Gos;
        Gos = GlobalFlock.AllFishes;

        Vector3 VCenter = Vector3.zero;
        Vector3 VAvoid  = Vector3.zero;
        Vector3 GoalPos = MyManager.GoalPos;

        float GSpeed = 0.1f;
        float Dist;
        int   GroupSize = 0;

        foreach (GameObject Go in Gos)
        {
            if (Go != this.gameObject)
            {
                Dist = Vector3.Distance(Go.transform.position, this.transform.position);
                if (Dist <= NeighbourDistance)
                {
                    VCenter += Go.transform.position;
                    GroupSize++;

                    //increase if the tank size increased
                    if (Dist < 2.0f)
                    {
                        VAvoid = VAvoid + (this.transform.position - Go.transform.position);
                    }

                    Flock AnotherFlock = Go.GetComponent <Flock> ();
                    GSpeed = GSpeed + AnotherFlock.Speed;
                }
            }
        }

        if (GroupSize > 0)
        {
            VCenter = VCenter / GroupSize + (GoalPos - this.transform.position);
            Speed   = GSpeed / GroupSize * SpeedMul;

            Vector3 Direction = (VCenter + VAvoid) - transform.position;
            if (Direction != Vector3.zero)
            {
                transform.rotation = Quaternion.Slerp(transform.rotation, Quaternion.LookRotation(Direction), RotationSpeed * Time.deltaTime);
            }
        }
    }
Example #16
0
    /// <summary>
    /// 设置屏幕安全区域(异形屏支持)
    /// </summary>
    /// <param name="safeRect">安全区域</param>
    public void ApplySafeRect(Rect safeRect)
    {
        var          rectTrans = this.UIDesktop.transform as RectTransform;
        CanvasScaler scaler    = Go.GetComponent <CanvasScaler>();

        // Convert safe area rectangle from absolute pixels to UGUI coordinates
        float rateX  = scaler.referenceResolution.x / Screen.width;
        float rateY  = scaler.referenceResolution.y / Screen.height;
        float posX   = (int)(safeRect.position.x * rateX);
        float posY   = (int)(safeRect.position.y * rateY);
        float width  = (int)(safeRect.size.x * rateX);
        float height = (int)(safeRect.size.y * rateY);

        float offsetMin = scaler.referenceResolution.y - posY - height;
        float offsetMax = scaler.referenceResolution.x - posX - width;

        rectTrans.offsetMin = new Vector2(posX, offsetMin);
        rectTrans.offsetMax = new Vector2(-offsetMax, -posY);
    }
Example #17
0
    /// <summary>
    /// 设置屏幕安全区域(异形屏支持)
    /// </summary>
    /// <param name="safeRect">安全区域</param>
    public void ApplySafeRect(Rect safeRect)
    {
        // 注意:安全区坐标系的原点为左下角
        var          rectTrans = this.UIDesktop.transform as RectTransform;
        CanvasScaler scaler    = Go.GetComponent <CanvasScaler>();

        // Convert safe area rectangle from absolute pixels to UGUI coordinates
        float rateX  = scaler.referenceResolution.x / Screen.width;
        float rateY  = scaler.referenceResolution.y / Screen.height;
        float posX   = (int)(safeRect.position.x * rateX);
        float posY   = (int)(safeRect.position.y * rateY);
        float width  = (int)(safeRect.size.x * rateX);
        float height = (int)(safeRect.size.y * rateY);

        float offsetMaxX = scaler.referenceResolution.x - width - posX;
        float offsetMaxY = scaler.referenceResolution.y - height - posY;

        rectTrans.offsetMin = new Vector2(posX, posY);               //锚框状态下的屏幕左下角偏移向量
        rectTrans.offsetMax = new Vector2(-offsetMaxX, -offsetMaxY); //锚框状态下的屏幕右上角偏移向量
    }
Example #18
0
    private void PlaceStartAndEndPipe()
    {
        foreach (GameObject Go in pipeGrid)
        {
            BgTile bgt = Go.GetComponent <BgTile>();

            //Start pipe
            if (bgt.transform.position.x == 0 && bgt.transform.position.y == 2)
            {
                bgt.pipeOnBg = Instantiate(HorizontalPipe, new Vector3(0, 2, 0), Quaternion.identity);
                // add to pipelist to enable waterflow
                pipeList.Add(bgt.pipeOnBg.GetComponent <Pipe>());
            }

            //End pipe
            if (bgt.transform.position.x == gridWidth - 1 && bgt.transform.position.y == 3)
            {
                endPipe      = Instantiate(HorizontalPipe, new Vector3(gridWidth - 1, 3, 0), Quaternion.identity);
                bgt.pipeOnBg = endPipe;
            }
        }
    }
Example #19
0
        void Update()
        {
            /***** Gestion du temps *****/
            changeTurn = true;

            if (!waiting)
            {
                if (InferenceEngine.tour == "Ours")
                {
                    foreach (GameObject Go in Niveau.list_element[0])
                    {
                        if (Go != null && Go.GetComponent <Element>().aJoue == false)
                        {
                            changeTurn = false;
                        }
                    }
                    foreach (GameObject Go in Niveau.list_element[1])
                    {
                        if (Go != null)
                        {
                            Go.GetComponent <Element>().flagIsDetected = false;
                        }
                    }
                }
                else
                {
                    foreach (GameObject Go in Niveau.list_element[1])
                    {
                        if (Go != null && Go.GetComponent <Element>().aJoue == false)
                        {
                            changeTurn = false;
                        }
                    }
                    foreach (GameObject Go in Niveau.list_element[0])
                    {
                        if (Go != null)
                        {
                            Go.GetComponent <Element>().flagIsDetected = false;
                        }
                    }
                }

                if (changeTurn == true)
                {
                    if (InferenceEngine.tour == "Ours")
                    {
                        foreach (GameObject Go in Niveau.list_element[0])
                        {
                            if (Go != null)
                            {
                                Go.GetComponent <Element>().aJoue = false;
                            }
                        }
                    }
                    else
                    {
                        foreach (GameObject Go in Niveau.list_element[1])
                        {
                            if (Go != null)
                            {
                                Go.GetComponent <Element>().aJoue = false;
                            }
                        }
                    }
                    StartCoroutine("ChangeTurn");
                }
            }
            /***** Fin Gestion du temps *****/

            /***** Gestion de la pause *****/
            if (Input.GetKeyDown(KeyCode.P) || Input.GetKeyDown(KeyCode.Escape))
            {
                if (pause)
                {
                    pause          = false;
                    Time.timeScale = 1;
                    GameObject.Find("Canvas").SetActive(false);
                }
                else
                {
                    pause          = true;
                    Time.timeScale = 0;
                    GameObject.Find("GameObject").transform.GetChild(0).gameObject.SetActive(true);
                }
            }
            /***** Fin Gestion de la pause *****/

            /***** Gestion de la santé *****/
            if (GameObject.FindGameObjectWithTag("Bunker") != null)
            {
                GameObject.Find("HealthValue").GetComponent <Image>().fillAmount = (float)(GameObject.FindGameObjectWithTag("Bunker").GetComponent <Element>().PV / 100);
            }
            /***** Fin Gestion de la santé *****/

            if (Input.GetKeyDown(KeyCode.K) && GameObject.FindGameObjectWithTag("Bunker") != null)
            {
                GameObject.FindGameObjectWithTag("Bunker").GetComponent <Element>().PV -= 5;
            }
            else if (GameObject.FindGameObjectWithTag("Bunker") == null)
            {
                GameObject.Find("HealthValue").GetComponent <Image>().fillAmount = 0;
            }
        }
        /// <summary>
        /// Shoots the main weapon for the ship in use
        /// </summary>
        protected virtual IEnumerator ShootMainWeapon(Vector2 Direction, float Spd = 10, int?ShotFrom = null)
        {
            CanShootMain = false;
            GameObject Go;

            if (!IsEm)
            {
                Go = GetMainWeaponObj();
            }
            else
            {
                Go = GetComponent <Enemies>().EmWeapons.GetOrb();
            }

            if (Go)
            {
                if (Go.name.Contains("Laser"))
                {
                    Go.GetComponent <LineRenderer>().SetPosition(0, transform.GetChild(0).position);
                    Go.GetComponent <LineRenderer>().SetPosition(1, new Vector3(transform.GetChild(0).position.x, transform.GetChild(0).position.y + 30, transform.GetChild(0).position.z));
                    Go.GetComponent <LineRenderer>().enabled = false;
                }

                Go.transform.position = MainPointToShootFrom().transform.position;
                Go.SetActive(true);


                Go.GetComponent <Damage>().DMG = (int)Ship.MainWeapon.Damage[(int)GM.ActiveStage];

                if (Go.GetComponent <MissileScript>())
                {
                    Go.GetComponent <MissileScript>().ShouldFindTarget = true;
                }
                else if (PlayerShip == Ships.UnityGunship)
                {
                    if (!IsFrozen)
                    {
                        StartCoroutine(UnityGunshipFreeze(Go));
                    }
                }
                else
                {
                    Go.GetComponent <Rigidbody2D>().velocity += Direction * Spd;
                }

                // Sets who shot the bullet if it has a value
                if (ShotFrom != null)
                {
                    Go.GetComponent <Damage>().SetPlayerShotFrom((int)ShotFrom);
                }

                // Wait for delay time before lettings the player shoot again
                yield return(new WaitForSeconds(Ship.MainWeapon.Delay));

                CanShootMain = true;
            }
            else
            {
                yield return(new WaitForSeconds(0));

                CanShootMain = true;
            }

            PlayerStats.mainShotsFired++;
        }
Example #21
0
 public override void SetPosition2D(Vector2 p)
 {
     Go.GetComponent <RectTransform>().anchoredPosition = p;
 }
Example #22
0
 protected override void Start()
 {
     LayoutElement = Go.GetComponent <LayoutElement>();
 }
    public void MoveToPublicAreaForFlat()
    {
        var Tut = GameManager.Instance.GetComponent <Tutorial> ();

        //		SelectedPublicArea = PublicAreas [i];
        CharacterOriginalPosition = PlayerManager.Instance.MainCharacter.transform.position;

        Camera.main.transform.position = new Vector3(212f, 4.8f, -10f);
//		transform.GetChild (0).GetComponent <SpriteRenderer> ().sprite = SelectedPublicArea.Background;
        GameObject Go;

        if (!Tut.HostPartyCreated)
        {
            SelectedPublicArea = PublicAreas [5];
            Go = Instantiate(SelectedPublicArea.BackgroundPrefab, new Vector3(211, 5, 0), Quaternion.identity) as GameObject;
        }
        else
        {
            Go = Instantiate(SelectedPublicArea.BackgroundPrefab, new Vector3(211, 5, 0), Quaternion.identity) as GameObject;
        }

        CurrentPublicArea = Go.GetComponent <MultiplayerPositions> ();
        Go.name           = "FlatPartyPublicArea";
        GameObject roomConcatiner = GameObject.Instantiate(HostPartyManager.Instance.FlatPartyRoomContainer, Vector3.zero, Quaternion.identity) as GameObject;

        roomConcatiner.transform.parent        = Go.transform;
        roomConcatiner.transform.localPosition = Vector3.zero;
        roomConcatiner.name = "FlatpartyRoomContainer";
        Camera.main.GetComponent <DragCamera1> ().enabled           = false;
        Camera.main.GetComponent <DragableCamera> ().enabled        = true;
        Camera.main.GetComponent <DragableCamera> ().RestrictedMinX = SelectedPublicArea.Starting_x;
        Camera.main.GetComponent <DragableCamera> ().RestrictedMaxX = SelectedPublicArea.Ending_x;
        Camera.main.GetComponent <DragableCamera> ().RestrictedMaxY = SelectedPublicArea.Starting_y;
        Camera.main.GetComponent <DragableCamera> ().RestrictedMinY = SelectedPublicArea.Ending_y;


        Camera.main.orthographicSize = 10f;

//		GameObject Flat = Instantiate (RoomPurchaseManager.Instance.RoomTypePrefeb [1], new Vector3 (212, -3, 0), Quaternion.identity) as GameObject;
//		Flat.name = "FlatPartyRoom";

        HostPartyManager.Instance.SelectedPartyDecor.Clear();
        SetRoomAndDecorForFlatParty();

        GameObject[] room       = GameObject.FindGameObjectsWithTag("SocietyRoom");
        int          randomRoom = UnityEngine.Random.Range(0, room.Length);

        if (Tut.HostPartyCreated)
        {
            ChatManager.Instance.MessageCountForFlatParty = 0;
            HostPartyManager.Instance.SpwanRealPlayerForFlatParty(room [randomRoom]);
        }
        else
        {
            // Spwan Offline player for flat party.
            HostPartyManager.Instance.SpwanPlayerForOfllineFlatParty(room [randomRoom]);
        }
        DisableWalls();
        //Delete all old messeage gameobjects in scene....
//		for (int x = 0; x < ChatManager.Instance.message_panel.childCount; x++) {
//			Destroy (ChatManager.Instance.message_panel.GetChild (x).gameObject);
//		}
    }