public void SaveDataAsset()
    {
        SyncCurrenItemAsset();

        if (itemAsset != null)
        {
            itemAsset.destroy_effect_code = UIUtil.GetInputValue(inputSpriteEffect);
            itemAsset.code = UIUtil.GetInputValue(inputSprite);

            float   rotationSpeed = -float.Parse(UIUtil.GetInputValue(inputRotationSpeed));
            Vector3 vectorSpeed   = Vector3.zero;

            if (GameDraggableEditor.GetCanvasType() == GameDraggableCanvasType.CANVAS_2D)
            {
                vectorSpeed = Vector3.zero.WithZ(rotationSpeed);
            }
            else
            {
                vectorSpeed = Vector3.zero.WithY(rotationSpeed);
            }

            itemAsset.speed_rotation.FromVector3(vectorSpeed);

            itemAsset.destructable = UIUtil.GetCheckboxValue(checkboxEditAssetDestructable);
            itemAsset.kinematic    = UIUtil.GetCheckboxValue(checkboxEditAssetKinematic);
            itemAsset.reactive     = UIUtil.GetCheckboxValue(checkboxEditAssetReactive);
            itemAsset.gravity      = UIUtil.GetCheckboxValue(checkboxEditAssetGravity);
        }
    }
 public void SyncCurrenItemAsset()
 {
     if (GameDraggableEditor.Instance != null)
     {
         itemAsset = GameDraggableEditor.GetCurrentLevelItemAsset();
     }
 }
    public void UpdateRotation(float val, bool deferSlider, bool deferInput)
    {
        if (itemAsset != null)
        {
            val = Mathf.Clamp(val, MIN_ROTATION_SPEED, MAX_ROTATION_SPEED);
            float sliderVal = NormalizeRotationSlider(val);

            if (!deferInput)
            {
                UIUtil.SetInputValue(inputRotationSpeed, val.ToString());
            }
            if (!deferSlider)
            {
                UIUtil.SetSliderValue(sliderRotationSpeed, sliderVal);
            }

            Vector3 posFrom = Vector3.zero;

            if (GameDraggableEditor.GetCanvasType() == GameDraggableCanvasType.CANVAS_2D)
            {
                posFrom = posFrom.WithZ(-val);
            }
            else
            {
                posFrom = posFrom.WithY(-val);
            }

            itemAsset.speed_rotation.FromVector3(posFrom);
        }
    }
Beispiel #4
0
    public void LoadSprite(string spriteCode)
    {
        if (gameLevelItemObject != null)
        {
            RemoveGameLevelItems();

            GameObject go = GameDraggableEditor.LoadSprite(
                gameLevelItemObject, spriteCode, Vector3.one);

            //LogUtil.Log("LoadSprite:exists:" + go != null);

            if (go != null)
            {
                //LogUtil.Log("LoadSprite:" + go.name);

                GameLevelSprite gameLevelSprite = go.GetComponent <GameLevelSprite>();

                if (gameLevelSprite != null)
                {
                    gameLevelSprite.gameDraggableLevelItem = this;

                    //LogUtil.Log("LoadSprite:gameLevelSprite:" + gameLevelSprite.name);
                }
                //go.transform.parent.transform.parent.transform.parent.transform.parent.position = Vector3.zero;
                //go.transform.parent.transform.parent.transform.parent.transform.parent.localPosition = Vector3.zero;
            }
        }
    }
    /*
     * IEnumerator LoadDataCo() {
     *
     *      yield return new WaitForSeconds(.1f);
     *
     *      if (listGridRoot != null) {
     *  foreach (Transform item in listGridRoot.transform) {
     *      Destroy(item.gameObject);
     *  }
     *
     *              List<AppContentAsset> assets = AppContentAssets.Instance.GetAll();
     *
     *      LogUtil.Log("Load AppContentAsset: assets.Count: " + assets.Count);
     *
     *              int i = 0;
     *
     *              int totalPoints = 0;
     *
     *      foreach(AppContentAsset asset in assets) {
     *
     *          GameObject item = NGUITools.AddChild(listGridRoot, listItemPrefab);
     *          item.name = "AssetItem" + i;
     *          item.transform.FindChild("LabelName").GetComponent<UILabel>().text = asset.display_name;
     *          //item.transform.FindChild("LabelDescription").GetComponent<UILabel>().text = achievement.description;
     *
     *                      GameObject gameLevelItemObject = item.transform.FindChild("GameLevelItemObject").gameObject;
     *
     *                      // clear current items
     *
     *                      foreach(Transform t in gameLevelItemObject.transform) {
     *                              Destroy(t.gameObject);
     *                      }
     *
     *                      GameObject go = GameShooterController.Instance.LoadSpriteUI(
     *                              gameLevelItemObject, asset.code, Vector3.one);
     *                      gameLevelItemObject.ChangeLayersRecursively("UILayer");
     *
     *                      float maxSize = 3;
     *
     *                      if(go != null) {
     *                              PackedSprite sprite = go.GetComponent<PackedSprite>();
     *                              if(sprite != null) {
     *
     *                                      float adjust = 1;
     *
     *                                      if(sprite.height > sprite.width) {
     *                                              if(sprite.height > maxSize) {
     *                                                      adjust = maxSize/sprite.height;
     *                                              }
     *                                      }
     *                                      else {
     *                                              if(sprite.width > maxSize) {
     *                                                      adjust = maxSize/sprite.width;
     *                                              }
     *                                      }
     *
     *                                      go.transform.localScale = go.transform.localScale.WithX(adjust).WithY(adjust).WithZ(adjust);
     *                              }
     *                      }
     *
     *                      item.transform.FindChild("ButtonGameLevelItemObject").GetComponent<UIButton>().name
     *                                      = "ButtonGameLevelItemObject$" + asset.code; ///levels[y].name;
     *
     *                      i++;
     *      }
     *
     *      yield return new WaitForEndOfFrame();
     *      listGridRoot.GetComponent<UIGrid>().Reposition();
     *      yield return new WaitForEndOfFrame();
     *
     * }
     * }
     */

    void OnInputClickEventHandler(string inputName, int cam)
    {
        LogUtil.Log("OnInputClickEventHandler: inputName:" + inputName);

        if (inputName == inputSprite.name)
        {
            actionState = UIPanelEditAssetActionState.SELECT_ITEM;
            GameDraggableEditor.ShowUIPanelDialogItems();
        }
        else if (inputName == inputSpriteEffect.name)
        {
            actionState = UIPanelEditAssetActionState.SELECT_EFFECT;
            GameDraggableEditor.ShowUIPanelDialogItems();
        }
    }
    public void UpdateSprite(string assetCode)
    {
        if (itemAsset != null)
        {
            itemAsset.code = assetCode;
            UIUtil.SetInputValue(inputSprite, itemAsset.code);
            UIUtil.SetLabelValue(labelAssetEdit, itemAsset.code);
            UIUtil.SetLabelValue(labelGameEditAssetSprite, GetItemAssetDisplayName(itemAsset.code));

            GameDraggableLevelItem levelItem = GameDraggableEditor.GetCurrentDraggableLevelItem();
            if (levelItem != null)
            {
                levelItem.LoadSprite(itemAsset.code);
            }
        }
    }
    void OnButtonClickEventHandler(string buttonName)
    {
        if (itemAsset != null)
        {
            if (buttonName == buttonGameEditAssetSave.name)
            {
                SaveDataAsset();
                ////GameDraggableEditor.ResetAssetPanelRemoveDeselect();
                actionState = UIPanelEditAssetActionState.NONE;
            }
            else if (buttonName == buttonGameEditAssetDelete.name)
            {
                GameDraggableLevelItem levelItem = GameDraggableEditor.GetCurrentDraggableLevelItem();
                if (levelItem != null)
                {
                    levelItem.DestroyMeAnimated();
                }

                ////GameDraggableEditor.ResetAssetPanelRemoveDeselect();
                actionState = UIPanelEditAssetActionState.NONE;
            }
            else if (buttonName == buttonGameEditAssetDeselect.name)
            {
                ////GameDraggableEditor.ResetAssetPanelRemoveDeselect();
                actionState = UIPanelEditAssetActionState.NONE;
            }
            else if (buttonName == buttonGameEditAssetSprite.name)
            {
                actionState = UIPanelEditAssetActionState.SELECT_ITEM;
                GameDraggableEditor.ShowUIPanelDialogItems();
            }
            else if (buttonName == buttonGameEditAssetSpriteEffect.name)
            {
                actionState = UIPanelEditAssetActionState.SELECT_EFFECT;
                GameDraggableEditor.ShowUIPanelDialogItems();
            }

            else if (buttonName == buttonGameEditAssetRotationReset.name)
            {
                UpdateRotation(0f, false, false);
            }
        }
    }
Beispiel #8
0
    public void LoadSpriteEffect(string spriteEffectCode)
    {
        if (gameLevelItemAsset != null)
        {
            GameObject go = GameDraggableEditor.LoadSpriteEffect(
                gameLevelItemObject,
                gameLevelItemAsset.destroy_effect_code,
                Vector3.one.WithX(3).WithY(3).WithZ(3) * .1f);

            if (go != null)
            {
                //PackedSprite sprite = go.GetComponent<PackedSprite>();
                //if(sprite != null) {
                //	sprite.PlayAnim(0);
                //}
                go.transform.parent = gameLevelItemObject.transform;
            }
        }
    }
    IEnumerator LoadDataCo()
    {
        yield return(new WaitForSeconds(.1f));

        if (listGridRoot != null)
        {
            foreach (Transform item in listGridRoot.transform)
            {
                Destroy(item.gameObject);
            }

            List <AppContentAsset> assets = AppContentAssets.Instance.GetAll();

            LogUtil.Log("Load AppContentAsset: assets.Count: " + assets.Count);

            int i = 0;

            //int totalPoints = 0;

            foreach (AppContentAsset asset in assets)
            {
                if (filterType != UIPanelDialogEditItemsFilter.all)
                {
                    if (asset.key != filterType)
                    {
                        continue;
                    }
                }

                GameObject item = NGUITools.AddChild(listGridRoot, listItemPrefab);
                item.name = "AssetItem" + i;
                item.transform.FindChild("LabelName").GetComponent <UILabel>().text = asset.display_name;
                //item.transform.FindChild("LabelDescription").GetComponent<UILabel>().text = achievement.description;

                GameObject gameLevelItemObject = item.transform.FindChild("GameLevelItemObject").gameObject;

                // clear current items

                foreach (Transform t in gameLevelItemObject.transform)
                {
                    Destroy(t.gameObject);
                }

                //LogUtil.Log("Load AppContentAsset: gameLevelItemObject.transform: " + gameLevelItemObject.transform.childCount);

                if (GameDraggableEditor.Instance == null)
                {
                    yield break;
                }
                //
                //LogUtil.Log("Load AppContentAsset: GameDraggableEditor: " + true);

                string assetCode = asset.code;
                if (assetCode.Contains("portal-"))
                {
                    assetCode = assetCode + "-sm";
                }

                GameObject go = GameDraggableEditor.LoadSpriteUI(
                    gameLevelItemObject, assetCode, Vector3.one);

                gameLevelItemObject.ChangeLayersRecursively("UIEditor");

                //LogUtil.Log("Load AppContentAsset: go: " + go);

                float maxSize = .8f;

                if (go != null)
                {
                    PackedSprite sprite = go.GetComponent <PackedSprite>();
                    if (sprite != null)
                    {
                        float adjust = 1;

                        if (sprite.height > sprite.width)
                        {
                            if (sprite.height > maxSize)
                            {
                                adjust = maxSize / sprite.height;
                            }
                        }
                        else
                        {
                            if (sprite.width > maxSize)
                            {
                                adjust = maxSize / sprite.width;
                            }
                        }

                        go.transform.localScale = go.transform.localScale.WithX(adjust).WithY(adjust).WithZ(adjust);
                    }
                    else
                    {
                        float adjust = 1;

                        Collider col = go.GetComponent <Collider>();
                        if (col != null)
                        {
                            Bounds bounds = col.bounds;

                            if (bounds.size.x > bounds.size.y)
                            {
                                if (bounds.size.y > maxSize)
                                {
                                    adjust = maxSize / bounds.size.x;
                                }
                            }
                            else
                            {
                                if (bounds.size.x > maxSize)
                                {
                                    adjust = maxSize / bounds.size.y;
                                }
                            }
                        }
                        adjust = adjust / 2;
                        go.transform.localScale = go.transform.localScale.WithX(adjust).WithY(adjust).WithZ(adjust);
                    }
                }

                item.transform.FindChild("ButtonGameLevelItemObject").GetComponent <UIButton>().name
                    = "ButtonGameLevelItemObject$" + asset.code;                             ///levels[y].name;

                if (filterType == UIPanelDialogEditItemsFilter.all)
                {
                }

                i++;
            }

            yield return(new WaitForEndOfFrame());

            listGridRoot.GetComponent <UIGrid>().Reposition();
            yield return(new WaitForEndOfFrame());
        }
    }