Example #1
0
    void _menuFunction(object value)
    {
        var argv = value as object[];

        if (null != argv && argv.Length == 2)
        {
            try
            {
                ScriptBinderItem component = argv[1] as ScriptBinderItem;
                if (null != component)
                {
                    component.component = argv[0] as UnityEngine.Object;
                }
            }
            catch (System.Exception ex)
            {
                UnityEngine.Debug.LogErrorFormat(ex.ToString());
            }
        }
    }
Example #2
0
    protected void OnScriptItemGUI()
    {
        for (int i = 0; i < components.arraySize; ++i)
        {
            var scriptBindItem = components.GetArrayElementAtIndex(i);
            if (null != scriptBindItem)
            {
                GUI.color = Color.gray;
                GUILayout.BeginVertical("GroupBox");

                //ScriptBinderItem
                SerializedProperty hashCode   = scriptBindItem.FindPropertyRelative("iHashCode");
                SerializedProperty component  = scriptBindItem.FindPropertyRelative("component");
                SerializedProperty varName    = scriptBindItem.FindPropertyRelative("varName");
                SerializedProperty locked     = scriptBindItem.FindPropertyRelative("locked");
                ScriptBinderItem   scriptItem = null;
                if (i < (target as ComScriptBinder).scriptItems.Length)
                {
                    scriptItem = (target as ComScriptBinder).scriptItems[i];
                }

                EditorGUILayout.BeginHorizontal();
                GUI.color           = Color.white;
                locked.boolValue    = EditorGUILayout.Toggle(locked.boolValue);
                GUI.enabled         = locked.boolValue;
                varName.stringValue = EditorGUILayout.TextField(varName.stringValue);
                GUI.enabled         = true;
                hashCode.intValue   = varName.stringValue.GetHashCode();
                GUI.color           = Color.white;
                EditorGUILayout.LabelField(hashCode.intValue.ToString(), GUILayout.MaxWidth(80));

                EditorGUILayout.EndHorizontal();

                EditorGUILayout.BeginHorizontal();
                component.objectReferenceValue = EditorGUILayout.ObjectField(component.objectReferenceValue, typeof(UnityEngine.Object), true) as UnityEngine.Object;
                if (null != component.objectReferenceValue)
                {
                    GameObject gameObject = component.objectReferenceValue as GameObject;
                    if (null == gameObject)
                    {
                        if (component.objectReferenceValue as Component)
                        {
                            gameObject = (component.objectReferenceValue as Component).gameObject;
                        }
                    }

                    if (GUILayout.Button("Select Component", "GV Gizmo DropDown", GUILayout.MaxWidth(120)))
                    {
                        Component[] coms = gameObject.GetComponents <Component>();

                        GenericMenu menu = new GenericMenu();
                        menu.AddItem(new GUIContent("GameObject"), component.objectReferenceValue is GameObject, _menuFunction, new object[] { gameObject, scriptItem });
                        if (null != coms)
                        {
                            for (int j = 0; j < coms.Length; ++j)
                            {
                                menu.AddItem(new GUIContent(coms[j].GetType().Name), component.objectReferenceValue == coms[j], _menuFunction, new object[] { coms[j], scriptItem });
                            }
                        }
                        menu.ShowAsContext();
                    }
                }
                EditorGUILayout.EndHorizontal();

                EditorGUILayout.BeginHorizontal();
                if (GUILayout.Button("insert"))
                {
                    if (i > 0)
                    {
                        components.InsertArrayElementAtIndex(i - 1);
                    }
                    else
                    {
                        components.InsertArrayElementAtIndex(i);
                    }
                }
                if (GUILayout.Button("append"))
                {
                    components.InsertArrayElementAtIndex(i);
                }
                GUI.enabled = !string.IsNullOrEmpty(varName.stringValue);
                if (GUILayout.Button("getcode"))
                {
                    string codeInfo = getCopyString(component, varName, false);
                    if (!string.IsNullOrEmpty(codeInfo))
                    {
                        GUIUtility.systemCopyBuffer = codeInfo;
                        UnityEngine.Debug.LogErrorFormat("<color=#00ff00>copy succeed : {0}</color>", codeInfo);
                    }
                }
                GUI.enabled = true;
                if (GUILayout.Button("  -  "))
                {
                    components.DeleteArrayElementAtIndex(i);
                }
                EditorGUILayout.EndHorizontal();

                GUILayout.EndVertical();
            }
        }

        GUI.color = Color.gray;
        EditorGUILayout.BeginVertical("GroupBox");
        GUI.color = Color.white;
        EditorGUILayout.BeginHorizontal();
        GUI.color = Color.green;
        EditorGUILayout.LabelField("Object TotalCount:", GUILayout.MinWidth(60));
        GUI.color   = Color.white;
        GUI.enabled = false;
        EditorGUILayout.IntField(components.arraySize, GUILayout.MinWidth(60));
        GUI.enabled = true;
        if (GUILayout.Button("  +   ", GUILayout.MinWidth(60)))
        {
            components.InsertArrayElementAtIndex(components.arraySize);
        }
        EditorGUILayout.EndHorizontal();
        EditorGUILayout.EndVertical();
    }