/// <summary>
        /// 绘制物体的特殊标示
        /// </summary>
        private void OnDrawHierarchyWindowItem(int instanceID, Rect selectionRect)
        {
            if (!allComponentDic.ContainsKey(instanceID) || allComponentDic[instanceID] == null)
            {
                UIProgramData data = GetComponentFromObj(instanceID);
                if (data == null)
                {
                    allComponentDic.Remove(instanceID);
                    return;
                }

                allComponentDic[instanceID] = data;
            }

            Texture2D icon = CheckProDataIsRight(instanceID) ? correctIcon : errorIcon;

            drawRect.x = selectionRect.x + selectionRect.width - 16;
            drawRect.y = selectionRect.y;

            GUI.DrawTexture(drawRect, icon);

            drawRect.y += 1;

            GameObject gameObj = EditorUtility.InstanceIDToObject(instanceID) as GameObject;

            UIProgramData[] dataList = gameObj.GetComponentsInChildren <UIProgramData>();

            string countStr = dataList.Length.ToString();

            drawRect.x -= countStr.Length * 10;

            GUI.Label(drawRect, countStr, style);
        }
        public UIExportData[] ExportData = null;    //所有要导出的数据

        /// <summary>
        /// 遍历指定物体节点下的所有UIProgramData,然后根据回调进行引用赋值
        /// </summary>
        /// <param name="thisObjRoot">物体根节点</param>
        /// <param name="handle">赋值回调</param>
        public static void ForEachDataByCode(GameObject thisObjRoot, SetUIProgramDataCompReference handle)
        {
            if (handle == null || thisObjRoot == null)
            {
                return;
            }

            UIProgramData[] allData = thisObjRoot.GetComponentsInChildren <UIProgramData>(true);
            if (null == allData || allData.Length == 0)
            {
                return;
            }

            for (int iLoop = 0; iLoop < allData.Length; iLoop++)
            {
                UIProgramData programData = allData[iLoop];
                if (null != programData.ExportData && programData.ExportData.Length > 0)
                {
                    for (int iIndex = 0; iIndex < programData.ExportData.Length; iIndex++)
                    {
                        UIExportData exportData = programData.ExportData[iIndex];
                        handle(programData, exportData);
                    }
                }
            }
        }
Esempio n. 3
0
 private void OnDisable()
 {
     thisData             = null;
     serObj               = null;
     prop_CreateClassName = null;
     prop_LocalClassName  = null;
     prop_ExportData      = null;
 }
        /// <summary>
        /// 检测变量数据是否合法
        /// </summary>
        private void CheckVariableData(UIProgramData pData)
        {
            for (int i = 0; i < pData.ExportData.Length; i++)
            {
                UIExportData data = pData.ExportData[i];
                if (data == null)
                {
                    continue;
                }

                //检测数据
                if (data.isArrayData)
                {
                    //检测数组是否为Null或者数组内有Null
                    bool isErrorData = false;
                    if (data.CompReferenceArray == null)
                    {
                        isErrorData = true;
                    }
                    else
                    {
                        foreach (var item in data.CompReferenceArray)
                        {
                            if (item == null)
                            {
                                isErrorData = true;
                                break;
                            }
                        }
                    }
                    if (isErrorData)
                    {
                        throw new UIExportDataException(string.Format("Variable data error.It is array data,but array is null or element is null. Variable name is {0} !",
                                                                      data.VariableName), pData);
                    }
                }
                else
                {
                    //非数组,检测引用是否为Null
                    if (data.CompReference == null)
                    {
                        throw new UIExportDataException(string.Format("Variable data error.It is null. Variable name is {0} !",
                                                                      data.VariableName), pData);
                    }
                }

                //检测变量名
                if (!CheckVariableOrClassName(data.VariableName))
                {
                    throw new UIExportDataException(string.Format("Variable name error.It is null or has blank space and variable name is {0} !",
                                                                  data.VariableName), pData);
                }
            }
        }
        public bool OnGUI()
        {
            //Press esc key to close this window
            Event eventData = Event.current;

            if (eventData.isKey)
            {
                if (eventData.keyCode == KeyCode.Escape)
                {
                    if (eventData.type == EventType.KeyDown)
                    {
                        Close();
                        return(true);
                    }
                }
            }

            //Processor null data
            if (pDataArray == null)
            {
                Close();
                return(true);
            }

            //Calculate max variable count
            for (int i = 0; i < pDataArray.Length; i++)
            {
                UIProgramData curObj = pDataArray[i];
                if (curObj == null)
                {
                    continue;
                }
                maxVariableCount = Mathf.Max(curObj.ExportData.Length, maxVariableCount);
            }

            //Title
            EditorGUILayout.BeginHorizontal();
            GUILayout.Label("Game Object", fieldWidthOption);
            for (int i = 0; i < maxVariableCount; i++)
            {
                DrawSplitChar();
                GUILayout.Label("Component Type " + (i + 1).ToString(), fieldWidthOption);
                DrawSplitChar();
                GUILayout.Label("Variable Name " + (i + 1).ToString(), fieldWidthOption);
            }
            EditorGUILayout.EndHorizontal();

            return(false);
        }
        protected void DrawUIProgramData(UIProgramData pData)
        {
            EditorGUILayout.BeginHorizontal();
            //Target game object
            EditorGUILayout.ObjectField(pData, pData.GetType(), true, fieldWidthOption);
            //Variables
            foreach (UIExportData data in pData.ExportData)
            {
                string type = "Null";

                if (data.isGameObjectRef)
                {
                    if (data.isArrayData)
                    {
                        type = "GameObject[]";
                    }
                    else
                    {
                        type = "GameObject";
                    }
                }
                else
                {
                    if (data.isArrayData)
                    {
                        if (data.CompReferenceArray == null || data.CompReferenceArray.Length == 0 || data.CompReferenceArray[0] == null)
                        {
                            type = "ArrayTypeError";
                        }
                        else
                        {
                            type = data.CompReferenceArray[0].GetType().Name + "[]";
                        }
                    }
                    else
                    {
                        type = data.CompReference.GetType().Name;
                    }
                }

                DrawSplitChar();
                GUILayout.Label(type, fieldWidthOption);

                DrawSplitChar();
                GUILayout.Label(data.VariableName, fieldWidthOption);
            }
            EditorGUILayout.EndHorizontal();
        }
        /// <summary>
        /// 遍历指定物体节点下的所有UIProgramData,然后根据字段名反射赋值
        /// </summary>
        /// <param name="rootObj">物体根节点</param>
        /// <param name="uiData">UIData对象</param>
        public static void ForEachDataByAttribute(GameObject rootObj, object uiData)
        {
            dataList.Clear();
            if (rootObj == null || uiData == null)
            {
                return;
            }

            UIProgramData[] allData = rootObj.GetComponentsInChildren <UIProgramData>(true);
            if (null == allData || allData.Length == 0)
            {
                return;
            }

            for (int iLoop = 0; iLoop < allData.Length; iLoop++)
            {
                UIProgramData programData = allData[iLoop];
                if (null != programData.ExportData && programData.ExportData.Length > 0)
                {
                    for (int iIndex = 0; iIndex < programData.ExportData.Length; iIndex++)
                    {
                        UIExportData exportData = programData.ExportData[iIndex];
                        dataList.Add(exportData);
                    }
                }
            }

            System.Reflection.FieldInfo[] fieldInfoArr = uiData.GetType().GetFields(System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Public);
            foreach (var field in fieldInfoArr)
            {
                object[] objAtts = field.GetCustomAttributes(typeof(UIDataAttribute), false);
                if (objAtts != null && objAtts.Length > 0)
                {
                    for (int j = 0, jMax = objAtts.Length; j < jMax; j++)
                    {
                        if (objAtts[j] == null)
                        {
                            continue;
                        }
                        UIDataAttribute dataAtt = objAtts[j] as UIDataAttribute;

                        SetFieldValue(uiData, field, dataAtt);
                    }
                }
            }
        }
        /// <summary>
        /// 找出所有需要创建的类,把名字存储到字典的键中
        /// </summary>
        private void FindAllClassNameSaveToDic(UIProgramData[] ProgramDatas, Dictionary <string, List <UIExportData> > dic_ClassAndVariables)
        {
            foreach (UIProgramData data in ProgramDatas)
            {
                if (data == null)
                {
                    continue;
                }

                if (!string.IsNullOrEmpty(data.CreateClassName))
                {
                    if (!dic_ClassAndVariables.ContainsKey(data.CreateClassName))
                    {
                        //证明类名不存在字典中,可以加入
                        dic_ClassAndVariables.Add(data.CreateClassName, new List <UIExportData>());
                    }
                    else
                    {
                        //证明字典中已经有这个类名,查找到类名所在的物体,抛出异常
                        if (data.CreateClassName.Equals(ClassName))
                        {
                            //证明这个类的创建名字是和主类相同
                            throw new UIExportDataException(string.Format("This game object has the same create class name with main and class name is {0}!",
                                                                          data.CreateClassName), data);
                        }
                        else
                        {
                            UIProgramData sameNameObj = null;
                            foreach (var item in ProgramDatas)
                            {
                                if (item != null && item != data && item.CreateClassName.Equals(data.CreateClassName))
                                {
                                    sameNameObj = item;
                                    break;
                                }
                            }
                            throw new UIExportDataException(string.Format("There are two game object has the same create class name and class name is {0}!",
                                                                          data.CreateClassName), data, sameNameObj);
                        }
                    }
                }
            }
        }
Esempio n. 9
0
        private void OnEnable()
        {
            thisData             = (target as UIProgramData);
            serObj               = serializedObject;
            prop_ExportData      = serObj.FindProperty("ExportData");
            prop_CreateClassName = serObj.FindProperty("CreateClassName");
            prop_LocalClassName  = serObj.FindProperty("LocalClassName");

            if (prop_ExportData != null && prop_ExportData.arraySize == 0)
            {
                //在添加脚本对象时,就初始化data的长度为1,不用手动设置长度,节省开发时间
                prop_ExportData.arraySize = 1;

                SerializedProperty firstProp = prop_ExportData.GetArrayElementAtIndex(0);
                firstProp.FindPropertyRelative("VariableName").stringValue           = thisData.name;
                firstProp.FindPropertyRelative("CompReference").objectReferenceValue = thisData.transform;
                serObj.ApplyModifiedProperties();
            }
        }
        /// <summary>
        /// 将UIProgramData中的变量添加到数组中
        /// </summary>
        private void AddContainerToVariablesList(string key, UIProgramData pData, UIProgramData[] ProgramDatas, Dictionary <string, List <UIExportData> > dic_ClassAndVariables)
        {
            //1:检测变量数据是否合法
            CheckVariableData(pData);

            if (dic_ClassAndVariables.ContainsKey(key))
            {
                List <UIExportData> dataList = dic_ClassAndVariables[key];
                foreach (var data in pData.ExportData)
                {
                    UIExportData sameData = dataList.Find(d => d.VariableName.Equals(data.VariableName));
                    if (sameData != null)
                    {
                        //证明已存在相同变量名,那就找出这个物体,抛异常
                        UIProgramData hasObj = null;
                        foreach (var item in ProgramDatas)
                        {
                            if (item == pData)
                            {
                                continue;
                            }
                            foreach (var exportData in item.ExportData)
                            {
                                if (exportData == sameData)
                                {
                                    hasObj = item;
                                    goto throwLine;
                                }
                            }
                        }
throwLine:
                        throw new UIExportDataException(string.Format("The variables has same and variable name is {0} !",
                                                                      data.VariableName), pData, hasObj);
                    }
                    dataList.Add(data);
                }
            }
            else
            {
                throw new UIExportDataException(string.Format("Don't has this class and class name is {0}", key), pData);
            }
        }
        /// <summary>
        /// 检测UI挂载的数据是否正确
        /// </summary>
        private bool CheckProDataIsRight(int instanceID)
        {
            if (allComponentDic[instanceID] == null)
            {
                return(false);
            }

            UIProgramData data = allComponentDic[instanceID];

            if (data.ExportData == null)
            {
                return(false);
            }

            foreach (var item in data.ExportData)
            {
                if (string.IsNullOrEmpty(item.VariableName))
                {
                    return(false);
                }

                if (item.isArrayData)
                {
                    foreach (var comp in item.CompReferenceArray)
                    {
                        if (comp == null)
                        {
                            return(false);
                        }
                    }
                }
                else
                {
                    if (item.CompReference == null)
                    {
                        return(false);
                    }
                }
            }

            return(true);
        }
Esempio n. 12
0
        private Dictionary <string, List <UIProgramData> > FormatUIProgramDataArrayToDic(UIProgramData[] pDataArray)
        {
            Dictionary <string, List <UIProgramData> > className_Data_Dic = new Dictionary <string, List <UIProgramData> >();

            for (int i = 0; i < pDataArray.Length; i++)
            {
                UIProgramData curObj = pDataArray[i];
                if (curObj == null || curObj.notExport)
                {
                    continue;
                }

                if (!string.IsNullOrEmpty(curObj.CreateClassName))
                {
                    AddValue(className_Data_Dic, curObj.CreateClassName, curObj);
                }

                string className = string.IsNullOrEmpty(curObj.LocalClassName) ? this.data.clsName : curObj.LocalClassName;

                AddValue(className_Data_Dic, className, curObj);
            }
            return(className_Data_Dic);
        }
Esempio n. 13
0
        public new void OnGUI()
        {
            if (base.OnGUI())
            {
                return;
            }

            DrawParagraphSplitSymbol();

            GUILayout.Label(data.errorLog);

            //List for variable
            for (int i = 0; i < pDataArray.Length; i++)
            {
                UIProgramData curObj = pDataArray[i];
                if (curObj == null)
                {
                    continue;
                }

                DrawUIProgramData(curObj);
            }
        }
Esempio n. 14
0
 private void AddValue(Dictionary <string, List <UIProgramData> > className_Data_Dic, string key, UIProgramData value)
 {
     if (!className_Data_Dic.ContainsKey(key))
     {
         className_Data_Dic[key] = new List <UIProgramData>();
     }
     className_Data_Dic[key].Add(value);
 }