Exemplo n.º 1
0
    protected override void Init()
    {
        mManager = new UIScriptCreatorManager();
        mManager.Init();

        mSearchField = new SearchField();
        mSearchField.downOrUpArrowKeyPressed += OnSearchFildEditor;
    }
Exemplo n.º 2
0
    /// <summary>
    /// 根据 GameObject 来更新数据
    /// </summary>
    public void UpdateDataByGo()
    {
        GameObject tGo = GetGo();

        if (tGo == null)
        {
            return;
        }

        mGo           = tGo;
        mTypeInstance = GetTypeInstance();

        mVarName = UIScriptCreatorManager.GetVariableName(tGo, mTypeName);
        mPath    = tGo.GetParenRelativePath(mRootGo, false);

        RefreshState();
    }
Exemplo n.º 3
0
    private void DrawBottomLeft(Rect pRect)
    {
        GUILayout.Label("游戏对象操作组件选择", "SettingsHeader");

        //调用GUILayoutUtility.GetRect 之后, 就相当于有这个 rect 的占用了
        Rect tRect = GUILayoutUtility.GetRect(new GUIContent(""), "OL box NoExpand", GUILayout.Width(pRect.width));

        if (Event.current.type == EventType.Repaint)
        {
            mLeftComponentSlectInfoRect         = tRect;
            mLeftComponentSlectInfoRect.width  -= 8;
            mLeftComponentSlectInfoRect.height += 6;
        }

        GameObject tSelectGo = Selection.activeGameObject;

        //处理选中状态
        if (mBLGoSelect != tSelectGo)
        {
            mBLGoSelect     = tSelectGo;
            mLeftSlectIndex = -1;
        }

        List <string> tTypeNameList = mManager.GetGoTypeNameList(Selection.activeGameObject);

        for (int i = 0; i < tTypeNameList.Count; ++i)
        {
            string tTypeName = tTypeNameList[i];

            bool tIsAdd    = mManager.IsAdd(tSelectGo, tTypeName);
            bool tIsSelect = mLeftSlectIndex == i;

            //修改背景颜色
            Color tColor = Color.white;
            if (tIsSelect)
            {
                tColor = mSelectColor;
            }
            else if (tIsAdd)
            {
                tColor = mAddColor;
            }

            Rect tBgBtnRect = new Rect(mLeftComponentSlectInfoRect.x,
                                       mLeftComponentSlectInfoRect.y + i * mLeftComponentSlectInfoRect.height,
                                       mLeftComponentSlectInfoRect.width,
                                       mLeftComponentSlectInfoRect.height);

            //绘制空label充当背景
            Color tTempColor = GUI.backgroundColor;
            GUI.backgroundColor = tColor;
            {
                GUI.Label(tBgBtnRect, "", "OL box NoExpand");
            }
            GUI.backgroundColor = tTempColor;

            Rect tContentRect = new Rect(tBgBtnRect);
            tContentRect.y     += 3f;
            tContentRect.x     += 3;
            tContentRect.width -= 5;

            GUILayout.BeginArea(tContentRect);
            GUILayout.BeginHorizontal();
            {
                //类型名
                GUILayout.Label(tTypeName);

                //按钮
                float tOpBtnWidth = 95f;
                if (tIsAdd)
                {
                    string tName         = UIScriptCreatorManager.GetVariableName(Selection.activeGameObject, tTypeName);
                    bool   tWaitToDelect = mManager.IsWaitToDelete(tName);
                    string tBtnName      = tWaitToDelect ? "取消待删" : "待删";
                    if (GUILayout.Button(tBtnName, GUILayout.Width(tOpBtnWidth)))
                    {
                        mManager.ToggleWaitToDelete(tName);
                    }
                }
                else
                {
                    if (GUILayout.Button("添加", GUILayout.Width(tOpBtnWidth)))
                    {
                        if (mManager.HasSameNameGoBind(tSelectGo))
                        {
                            //已有同名对象的被绑定了
                            mSearchFieldStr = tSelectGo.name;
                            ShowNotification(new GUIContent("添加失败, 已有同名的GameObject 绑定了, 请修改命名后再添加\n右边已筛选出名字相同的元素"));
                        }
                        else
                        {
                            mManager.AddNewUIElement(tSelectGo, tTypeName);
                            UpdateFilterElementList();
                        }
                    }
                }
            }
            GUILayout.EndHorizontal();
            GUILayout.EndArea();

            //背景点击响应
            //放在单个cell的绘制最后, 这样如果前面有响应事件的ui, 就会消耗掉这个事件, 这边就不会检测到
            //ps: Unity显示的ui 是按显示顺序的先后来检测点击的, 先显示的会优先检测到事件, 用完可能会标记消耗, 后面就用不了了
            //根据上面的规则, ig: 两个按钮重叠, 点击后, 被覆盖到的那个会响应, 前面那个不会
            if (Event.current.type == EventType.MouseDown && tBgBtnRect.Contains(Event.current.mousePosition))
            {
                if (mLeftSlectIndex == i)
                {
                    mLeftSlectIndex = -1;
                }
                else
                {
                    mLeftSlectIndex = i;
                }
            }
        }
    }