Esempio n. 1
0
    static void CreateSpriteUGUIPrefab()
    {
        string[] guid = Selection.assetGUIDs;
        string[] path = new string[] { AssetDatabase.GUIDToAssetPath(guid[0]) };
        Debug.Log(path[0]);
        string[] assets = AssetDatabase.FindAssets("t:texture2D", path);

        GameObject go     = new GameObject("SpritePrefab");
        SpriteCtrl spCtrl = go.AddComponent <SpriteCtrl>();

        for (int i = 0; i < assets.Length; i++)
        {
            string spritePath = AssetDatabase.GUIDToAssetPath(assets[i]);
            Debug.Log(spritePath);
            spCtrl.Add(AssetDatabase.LoadAssetAtPath <Sprite>(spritePath));
        }

        //path[0] = Application.dataPath + "/Resources/Prefabs";
        GameObject obj = PrefabUtility.CreatePrefab(path[0] + "/sprite.prefab", go, ReplacePrefabOptions.ConnectToPrefab);

        DestroyImmediate(go);
        AssetDatabase.SaveAssets();
        AssetDatabase.Refresh();
    }
Esempio n. 2
0
    // Use this for initialization
    void Start()
    {
        //Text = Tools.GetScenesObj("UI").transform.Find("TextGroup/gjx").gameObject;
        GraphicRaycaster gr = Tools.GetScenesObj("UI").transform.Find("InprojectionIgnoreCanvas").GetComponent <GraphicRaycaster>();

        GCSeriesRaycaster gcr = Tools.GetScenesObj("UI").transform.Find("InprojectionIgnoreCanvas").GetComponent <GCSeriesRaycaster>();

        GraphicRaycaster  gr1  = GetComponent <GraphicRaycaster>();
        GCSeriesRaycaster gcr1 = GetComponent <GCSeriesRaycaster>();

        gr1 = gr;
        gcr = gcr1;


        Debug.Log("ToolBox");

        simpleDrag = Tools.GetScenesObj("SimpleDrag").GetComponent <SimpleDrag>();

        objectsList.Clear();

        //初始化工具箱内部物品
        spCtrl = Main.instance.spCtrl;
        Transform  content    = GetComponentInChildren <ContentSizeFitter>().transform;
        GameObject itemSource = ResManager.GetPrefab("Prefabs/Item");

        itemSource.transform.SetParent(content);
        BoxItem item = itemSource.GetComponent <BoxItem>();

        item.SetSprite(spCtrl[1]);
        item.name = spCtrl[1].name;
        item.transform.localScale = Vector3.one;

        for (int i = 2; i <= spCtrl.Length; i++)
        {
            GameObject obj = Instantiate(itemSource);
            obj.transform.SetParent(content);
            item = obj.GetComponent <BoxItem>();
            item.SetSprite(spCtrl[i]);
            item.name = spCtrl[i].name;
            obj.transform.localScale = Vector3.one;
        }

        //工具箱事件的点击注册
        GameObject boxbtn = transform.Find("Boxbtn").gameObject;

        UGUIEventListener.Get(boxbtn).onPointUp = (GameObject go) =>
        {
            //Text.transform.localScale = Vector3.one;
            Image img = go.GetComponent <Image>();
            if (img.sprite == boxNormal)
            {
                img.sprite = boxClick;
            }
            else
            {
                img.sprite = boxNormal;
                //发送箱子关闭事件
                if (selectFinish) //开始播放
                {
                    PlayAnimation();
                }
            }

            ShowPanel();//控制工具箱的显示和隐藏
        };


        //视图隐藏
        panel = transform.Find("bg");
        panel.gameObject.SetActive(false);

        GlobalEntity.GetInstance().AddListener <GameObject>(EventEnum.Click, ItemClickCallback);

        string pName = transform.parent.name;
        string tip   = "请打开工具箱选择元素";

        Tip(tip);
    }