Example #1
0
        void ShowStateList(SerializedProperty stateList, string label)
        {
            var count = stateList.arraySize;

            // FIXME: should be replaced with DelayedIntField in 5.3
            count = EditorGUILayout.IntField("State Count", count);
            count = Mathf.Max(count, 1);

            // enlarge/shrink the list when the size is changed
            while (count > stateList.arraySize)
                stateList.InsertArrayElementAtIndex(stateList.arraySize - 1);
            while (count < stateList.arraySize)
                stateList.DeleteArrayElementAtIndex(stateList.arraySize - 1);

            EditorGUI.indentLevel ++;

            for (var i = 0; i < stateList.arraySize; i++)
            {
                var data = stateList.GetArrayElementAtIndex(i);
                var label_i = new GUIContent(label + " " + i);
                EditorGUILayout.PropertyField(data, label_i);
            }

            EditorGUI.indentLevel --;
        }
Example #2
0
        void ShowAnimationList(SerializedProperty animations)
        {
            var count = animations.arraySize;

            // FIXME: should be replaced with DelayedIntField in 5.3
            count = EditorGUILayout.IntField("Animation Count", count);
            count = Mathf.Max(count, 1);

            // enlarge/shrink the list when the size is changed
            while (count > animations.arraySize)
                animations.InsertArrayElementAtIndex(animations.arraySize - 1);
            while (count < animations.arraySize)
                animations.DeleteArrayElementAtIndex(animations.arraySize - 1);

            EditorGUI.indentLevel++;

            for (var i = 0; i < animations.arraySize; i++)
            {
                var data = animations.GetArrayElementAtIndex(i);
                var label_i = new GUIContent("Animation " + i);
                EditorGUILayout.PropertyField(data, label_i);
            }

            EditorGUI.indentLevel--;
        }
Example #3
0
 public static void Show(SerializedProperty list)
 {
     EditorGUILayout.PropertyField(list);
     EditorGUI.indentLevel += 1;
     if (list.isExpanded)
     {
         EditorGUILayout.PropertyField(list.FindPropertyRelative("Array.size"));
         //EditorGUILayout.BeginHorizontal();
         //EditorGUILayout.IntField("X", 0);
         //EditorGUILayout.IntField("Y", 0);
         //EditorGUILayout.IntField("Z", 0);
         //EditorGUILayout.EndHorizontal();
         if (list.arraySize>0)
             for (int i = 0; i < list.arraySize; i++)
             {
                 EditorGUILayout.BeginHorizontal();
                 EditorGUILayout.PropertyField(list.GetArrayElementAtIndex(i),GUIContent.none);
                 ShowButtons(list,i);
                 EditorGUILayout.EndHorizontal();
             }
         else
         {
             if (GUILayout.Button(addButtonContent))
                 list.InsertArrayElementAtIndex(0);
         }
     }
     EditorGUI.indentLevel -= 1;
 }
 public static void UpdateTransformMask(SerializedProperty transformMask, string[] refTransformsPath, string[] humanTransforms)
 {
   // ISSUE: object of a compiler-generated type is created
   // ISSUE: variable of a compiler-generated type
   AvatarMaskUtility.\u003CUpdateTransformMask\u003Ec__AnonStorey89 maskCAnonStorey89 = new AvatarMaskUtility.\u003CUpdateTransformMask\u003Ec__AnonStorey89();
   // ISSUE: reference to a compiler-generated field
   maskCAnonStorey89.refTransformsPath = refTransformsPath;
   transformMask.ClearArray();
   // ISSUE: object of a compiler-generated type is created
   // ISSUE: variable of a compiler-generated type
   AvatarMaskUtility.\u003CUpdateTransformMask\u003Ec__AnonStorey8A maskCAnonStorey8A = new AvatarMaskUtility.\u003CUpdateTransformMask\u003Ec__AnonStorey8A();
   // ISSUE: reference to a compiler-generated field
   maskCAnonStorey8A.\u003C\u003Ef__ref\u0024137 = maskCAnonStorey89;
   // ISSUE: reference to a compiler-generated field
   // ISSUE: reference to a compiler-generated field
   // ISSUE: reference to a compiler-generated field
   // ISSUE: reference to a compiler-generated field
   // ISSUE: reference to a compiler-generated field
   for (maskCAnonStorey8A.i = 0; maskCAnonStorey8A.i < maskCAnonStorey89.refTransformsPath.Length; maskCAnonStorey8A.i = maskCAnonStorey8A.i + 1)
   {
     // ISSUE: reference to a compiler-generated field
     transformMask.InsertArrayElementAtIndex(maskCAnonStorey8A.i);
     // ISSUE: reference to a compiler-generated field
     // ISSUE: reference to a compiler-generated field
     // ISSUE: reference to a compiler-generated field
     transformMask.GetArrayElementAtIndex(maskCAnonStorey8A.i).FindPropertyRelative("m_Path").stringValue = maskCAnonStorey89.refTransformsPath[maskCAnonStorey8A.i];
     // ISSUE: reference to a compiler-generated method
     bool flag = humanTransforms == null || ArrayUtility.FindIndex<string>(humanTransforms, new Predicate<string>(maskCAnonStorey8A.\u003C\u003Em__14A)) != -1;
     // ISSUE: reference to a compiler-generated field
     transformMask.GetArrayElementAtIndex(maskCAnonStorey8A.i).FindPropertyRelative("m_Weight").floatValue = !flag ? 0.0f : 1f;
   }
 }
Example #5
0
 public void AttackPatternField(SerializedProperty attackPatterns)
 {
     Vector3 moveRemove = new Vector3(-1f, -1f, 0f);
     int c = attackPatterns.FindPropertyRelative ("Array.size").intValue;
     if(c < 1)
     {
         attackPatterns.InsertArrayElementAtIndex(0);
         attackPatterns.GetArrayElementAtIndex(0).objectReferenceValue = gameObject.GetComponent<AbstractAttackPattern>();
     }
     for(int i = 0; i < c; i++)
     {
         EditorGUILayout.BeginHorizontal();
         SerializedProperty arrayElement = attackPatterns.GetArrayElementAtIndex(i);
         AbstractAttackPattern ap = (AbstractAttackPattern)arrayElement.objectReferenceValue;
         EditorGUILayout.PropertyField(arrayElement, new GUIContent((ap != null) ? GetAttackPatternName(ap) : i.ToString()));
         moveRemove = DanmakuEditorUtils.UpDownRemoveButtons(moveRemove, c, i, false);
         EditorGUILayout.EndHorizontal();
     }
     if (moveRemove.y >= 0)
     {
         int removeIndex = (int)moveRemove.y;
         if(attackPatterns.GetArrayElementAtIndex(removeIndex).objectReferenceValue != null)
         {
             attackPatterns.DeleteArrayElementAtIndex(removeIndex);
         }
         attackPatterns.DeleteArrayElementAtIndex(removeIndex);
     }
     if (moveRemove.x >= 0)
     {
         int moveIndex = (int)moveRemove.x;
         if (moveRemove.z > 0)
         {
             attackPatterns.MoveArrayElement (moveIndex, moveIndex + 1);
         }
         if (moveRemove.z < 0)
         {
             attackPatterns.MoveArrayElement (moveIndex, moveIndex - 1);
         }
     }
     if (GUILayout.Button("Add"))
     {
         attackPatterns.InsertArrayElementAtIndex(c);
     }
 }
        /// <summary>Add a new array element at the end of an array.</summary>
        /// <param name="array">The array to add a new element to.</param>
        /// <param name="index">Index position where to add the array element.</param>
        /// <returns><see cref="SerializedProperty"/> for the new array element.</returns>
        public static SerializedProperty AddArrayElement(SerializedProperty array, int index)
        {
            if (!array.isArray) {
                Debug.LogError("Specified property is not an array");
                return null;
            }
            array.InsertArrayElementAtIndex(index);

            return array.GetArrayElementAtIndex(index - 1);
        }
Example #7
0
    private void InitNewGrid(int newSize)
    {
        cells.ClearArray();

        for (int i = 0; i < newSize; i++)
        {
            cells.InsertArrayElementAtIndex(i);
            SerializedProperty row = GetRowAt(i);

            for (int j = 0; j < newSize; j++)
            {
                row.InsertArrayElementAtIndex(j);
            }
        }
    }
    private void LoadQuests()
    {
        // Reset properties
        actProperty = serializedObject.FindProperty("act");
        sceneProperty = serializedObject.FindProperty("scene");
        questListProperty = serializedObject.FindProperty("questList");

        TextAsset[] questsList=ParleyMenu.GetActSceneQuests(ParleyMenu.GetActs()[actProperty.intValue],ParleyMenu.GetActsScenes()[ParleyMenu.GetActs()[actProperty.intValue]][sceneProperty.intValue]).ToArray();

        questListProperty.ClearArray();

        for (int x=0;x<questsList.Length;x++){
            questListProperty.InsertArrayElementAtIndex(x);
            questListProperty.GetArrayElementAtIndex(x).objectReferenceValue=questsList[x];
        }
    }
Example #9
0
 static void ShowButtons(SerializedProperty list, int index)
 {
     if (GUILayout.Button(moveButtonContent, EditorStyles.miniButtonLeft, miniButtonWidth)) {
         list.MoveArrayElement(index, index + 1);
     }
     if (GUILayout.Button(duplicateButtonContent, EditorStyles.miniButtonMid, miniButtonWidth)) {
         list.InsertArrayElementAtIndex(index);
     }
     if (GUILayout.Button(deleteButtonContent, EditorStyles.miniButtonRight, miniButtonWidth)) {
         int oldSize = list.arraySize;
         list.DeleteArrayElementAtIndex(index);
         if (list.arraySize == oldSize) {
             list.DeleteArrayElementAtIndex(index);
         }
     }
 }
 public static void DrawList(ref Rect position, SerializedProperty property)
 {
     position.height = 16;
     EditorGUI.PropertyField (position, property);
     position.y += 18;
     EditorGUI.indentLevel++;
     if (property.isExpanded) {
         Rect buttonPosition;
         for (int i = 0; i < property.arraySize; i++) {
             buttonPosition = position;
             buttonPosition.height = 16;
             buttonPosition.width = 20;
             buttonPosition.x += position.width - 62;
             if (GUI.Button (buttonPosition, moveButtonContent, EditorStyles.miniButtonLeft)) {
                 property.MoveArrayElement (i, i + 1);
             }
             buttonPosition.x += 20;
             if (GUI.Button (buttonPosition, duplicateButtonContent, EditorStyles.miniButtonMid)) {
                 property.InsertArrayElementAtIndex (i);
             }
             buttonPosition.x += 20;
             if (GUI.Button (buttonPosition, deleteButtonContent, EditorStyles.miniButtonRight)) {
                 int oldsize = property.arraySize;
                 property.DeleteArrayElementAtIndex (i);
                 if (oldsize == property.arraySize) {
                     property.DeleteArrayElementAtIndex (i);
                 }
             } else {
                 DrawProperty (ref position, property.GetArrayElementAtIndex (i), true);
             }
         }
         buttonPosition = position;
         buttonPosition.height = 16;
         buttonPosition.width -= EditorGUI.indentLevel * 16;
         buttonPosition.x += EditorGUI.indentLevel * 16;
         if (GUI.Button (buttonPosition, addButtonContent, EditorStyles.miniButton)) {
             property.arraySize += 1;
         }
         position.y += 18;
     }
     EditorGUI.indentLevel--;
 }
Example #11
0
    private static void ShowButtons(SerializedProperty list, int index)
    {
        if (GUILayout.Button(duplicateButtonContent, EditorStyles.miniButtonLeft, miniButtonWidth))
        {
            list.InsertArrayElementAtIndex(index);
            if (index < list.arraySize - 2)
            {
                Vector3 vector1 = list.GetArrayElementAtIndex(index).vector3Value;
                Vector3 vector2 = list.GetArrayElementAtIndex(index+2).vector3Value;
                Vector3 newVector = (vector2 + vector1)/2;
                newVector.z = vector1.z;
                list.GetArrayElementAtIndex(index + 1).vector3Value = newVector;
            }

        }
        if (GUILayout.Button(deleteButtonContent, EditorStyles.miniButtonRight, miniButtonWidth))
        {
            list.DeleteArrayElementAtIndex(index);
        }
    }
Example #12
0
    //添加新的元素
    public void Add(string key, Object obj)
    {
        UnityEditor.SerializedObject serializedObject = new UnityEditor.SerializedObject(this);
        //根据PropertyPath读取数据
        //如果不知道具体的格式,可以右键用文本编辑器打开一个prefab文件(如Bundles/UI目录中的几个)
        //因为这几个prefab挂载了ReferenceCollector,所以搜索data就能找到存储的数据
        UnityEditor.SerializedProperty dataProperty = serializedObject.FindProperty("data");
        int i;

        //遍历data,看添加的数据是否存在相同key
        for (i = 0; i < data.Count; i++)
        {
            if (data[i].key == key)
            {
                break;
            }
        }
        //不等于data.Count意为已经存在于data List中,直接赋值即可
        if (i != data.Count)
        {
            //根据i的值获取dataProperty,也就是data中的对应ReferenceCollectorData,不过在这里,是对Property进行的读取,有点类似json或者xml的节点
            UnityEditor.SerializedProperty element = dataProperty.GetArrayElementAtIndex(i);
            //对对应节点进行赋值,值为gameobject相对应的fileID
            //fileID独一无二,单对单关系,其他挂载在这个gameobject上的script或组件会保存相对应的fileID
            element.FindPropertyRelative("gameObject").objectReferenceValue = obj;
        }
        else
        {
            //等于则说明key在data中无对应元素,所以得向其插入新的元素
            dataProperty.InsertArrayElementAtIndex(i);
            UnityEditor.SerializedProperty element = dataProperty.GetArrayElementAtIndex(i);
            element.FindPropertyRelative("key").stringValue = key;
            element.FindPropertyRelative("gameObject").objectReferenceValue = obj;
        }
        //应用与更新
        UnityEditor.EditorUtility.SetDirty(this);
        serializedObject.ApplyModifiedProperties();
        serializedObject.UpdateIfRequiredOrScript();
    }
Example #13
0
        public static void AddTag(string _tag)
        {
#if UNITY_EDITOR
            UnityEngine.Object[] _asset = UnityEditor.AssetDatabase.LoadAllAssetsAtPath("ProjectSettings/TagManager.asset");
            if ((_asset != null) && (_asset.Length > 0))
            {
                UnityEditor.SerializedObject   _object = new UnityEditor.SerializedObject(_asset[0]);
                UnityEditor.SerializedProperty _tags   = _object.FindProperty("tags");

                for (int i = 0; i < _tags.arraySize; ++i)
                {
                    if (_tags.GetArrayElementAtIndex(i).stringValue == _tag)
                    {
                        return;
                    }
                }

                _tags.InsertArrayElementAtIndex(0);
                _tags.GetArrayElementAtIndex(0).stringValue = _tag;
                _object.ApplyModifiedProperties();
                _object.Update();
            }
#endif
        }
		public static void Draw (Rect _position, SerializedProperty _arrayProperty, GUIContent _label, eArrayOptions _options)
		{
			int _originalIndentLevel	= EditorGUI.indentLevel;
			int _count					= _arrayProperty.arraySize;
			bool _showNameWithFoldout	= (_options & eArrayOptions.SHOW_NAME_WITH_FOLDOUT) != 0;
			bool _showArraySize			= (_options & eArrayOptions.SHOW_ARRAY_SIZE) != 0;

			// Height used for primitive properties and buttons
			float _singleLineHeight		= EditorGUIUtility.singleLineHeight;
			
			// Calculate rect
			float _positionY			= _position.y;

			// Rect for array name
			Rect _nameRect				= new Rect(_position.x, _positionY, _position.width, _singleLineHeight);
			_positionY					+= (_singleLineHeight + kSpacingPixels);
			
			// Show array name
			if (_showNameWithFoldout)
			{
				_arrayProperty.isExpanded	= EditorGUI.Foldout(_nameRect, _arrayProperty.isExpanded, _label);

				// Indent to next level
				EditorGUI.indentLevel++;
			}
			else
			{
				EditorGUI.LabelField(_nameRect, _label);
			}

			// Is foldout enabled, then dont show the rest of the elements
			if (!_arrayProperty.isExpanded)
			{
				// Reset indentation level
				EditorGUI.indentLevel	= _originalIndentLevel;
				return;
			}

			// Show array size
			if (_showArraySize && _count != 0)
			{
				// Rect for array Length
				Rect _sizeRect		= new Rect(_position.x, _positionY, _position.width, _singleLineHeight);
				_positionY			+= (_singleLineHeight + kSpacingPixels);

				// Check if size value changes
				EditorGUI.BeginChangeCheck();
				int _newSize		= EditorGUI.IntField(_sizeRect, "Size", _count);

				if (EditorGUI.EndChangeCheck())
					_arrayProperty.arraySize	= _newSize;
			}			

			// If there are no elements then we will show button to add elements
			if (_count == 0)
			{
				// Rect for add button
				Rect _addButtonRect	= new Rect(_position.x, _positionY, _position.width, _singleLineHeight);
				_positionY			+= (_singleLineHeight + kSpacingPixels);

				if (GUI.Button(_addButtonRect, "Add"))
					_arrayProperty.InsertArrayElementAtIndex(0);
			}
			else
			{
				// If there are elements then we will show its contents
				for (int _iter = 0; _iter < _count; _iter++)
				{
					// Get element property
					SerializedProperty _elementProperty	= _arrayProperty.GetArrayElementAtIndex(_iter);
					float _elementHeight				= EditorGUI.GetPropertyHeight(_elementProperty);

					// Rect for element, edit buttons
					Rect _elementRect		= new Rect(_position.x, _positionY, _position.width, _elementHeight);
					_positionY				+= _elementHeight;
					Rect _deleteButtonRect	= new Rect(_position.x + _position.width - kEditButtonWidth, _positionY, 
					                                  kEditButtonWidth, _singleLineHeight);
					Rect _addButtonRect		= new Rect(_deleteButtonRect.x - kEditButtonWidth, _positionY, 
					                                kEditButtonWidth, _singleLineHeight);
					_positionY				+= _singleLineHeight + kSpacingPixels;

					// Grouping element and buttons
					EditorGUI.PropertyField(_elementRect,
					                        _elementProperty, 
					                        new GUIContent("# " + (_iter + 1).ToString() + ":"), 
					                        true);
					
					if (GUI.Button(_addButtonRect, "+"))
					{
						_arrayProperty.InsertArrayElementAtIndex(0);
						break;
					}
					
					if (GUI.Button(_deleteButtonRect, "-"))
					{
						_arrayProperty.DeleteArrayElementAtIndex(_iter);
						break;
					}
				}
			}

			// Reset indentation level
			EditorGUI.indentLevel	= _originalIndentLevel;
		}
 public static void DrawListLayout(SerializedProperty property)
 {
     EditorGUILayout.PropertyField (property);
     EditorGUI.indentLevel++;
     if (property.isExpanded) {
         for (int i = 0; i < property.arraySize; i++) {
             EditorGUILayout.BeginHorizontal ();
             EditorGUILayout.PropertyField (property.GetArrayElementAtIndex (i), true);
             if (GUILayout.Button (moveButtonContent, EditorStyles.miniButtonLeft, GUILayout.Width(20))) {
                 property.MoveArrayElement (i, i + 1);
             }
             if (GUILayout.Button (duplicateButtonContent, EditorStyles.miniButtonMid, GUILayout.Width(20))) {
                 property.InsertArrayElementAtIndex (i);
             }
             if (GUILayout.Button (deleteButtonContent, EditorStyles.miniButtonRight, GUILayout.Width(20))) {
                 int oldsize = property.arraySize;
                 property.DeleteArrayElementAtIndex (i);
                 if (oldsize == property.arraySize) {
                     property.DeleteArrayElementAtIndex (i);
                 }
             }
             EditorGUILayout.EndHorizontal ();
         }
         if (GUILayout.Button (addButtonContent, EditorStyles.miniButton)) {
             property.arraySize += 1;
         }
     }
     EditorGUI.indentLevel--;
 }
    void DrawIntList(Rect displaySize, SerializedProperty intList, string type)
    {
        EditorGUIUtility.LookLikeControls();
        var currentY = displaySize.y;

        for (int i = 0; i < intList.arraySize; i++)
        {
            Rect lineDisplayRect = new Rect(displaySize.x + displaySize.width - 130, currentY, 100, 16);
            Rect removeButtonRect = new Rect(lineDisplayRect.x + lineDisplayRect.width, currentY, 30, 16);

            int validateFirst = EditorGUI.IntField(lineDisplayRect, intList.GetArrayElementAtIndex(i).intValue);
            if (validateFirst > 1)
            {
                intList.GetArrayElementAtIndex(i).intValue = validateFirst;
            }
            if (GUI.Button(removeButtonRect, "-"))
            {
                intList.DeleteArrayElementAtIndex(i);
                return;
            }
            currentY += 16;
        }
        Rect AddButtonRect = new Rect(displaySize.x, currentY, displaySize.width, 16);

        if (GUI.Button(AddButtonRect, "+ Add New " + type))
        {
            intList.InsertArrayElementAtIndex(intList.arraySize);
        }
    }
        private void DrawInputBehaviorSettings(SerializedProperty settingsArray) {
            if(settingsArray == null || !settingsArray.isArray) return;

            EditorGUILayout.Space();

            EditorGUILayout.HelpBox(
                "You can define a list of Input Behaviors to be shown to the user for modification. If enabled, new controls will be displayed so the user can modify these settings. " +
                "This is useful if you need to allow the user to set certain per-Action sensitivity levels such as Mouse Look Sensitivity."
            , MessageType.Info);

            EditorGUILayout.Space();

            int[] inputBehaviorIds = userData.GetInputBehaviorIds();
            string[] inputBehaviorNames = userData.GetInputBehaviorNames();

            int count = settingsArray.arraySize;
            for(int i = 0; i < count; i++) {

                using(new EditorGUILayoutSection(true, style_mapSetBkg)) {

                    SerializedProperty setting = settingsArray.GetArrayElementAtIndex(i);
                    if(setting == null) continue;

                    GUILayout.Space(20f);
                    SerializedProperty inputBehaviorId = setting.FindPropertyRelative("_inputBehaviorId");
                    DrawPopupProperty(new GUIContent("Input Behavior", "The Input Behavior that will be displayed to the user for modification."), inputBehaviorIds, inputBehaviorNames, inputBehaviorId); // NOTE: mapCategoryId tool tip from Attribute is always NULL!
                    int selectedIndex = System.Array.IndexOf<int>(inputBehaviorIds, inputBehaviorId.intValue);
                    if(selectedIndex < 0) continue;

                    // Display settings

                    SerializedProperty labelLanguageKey = setting.FindPropertyRelative("_labelLanguageKey");

                    SerializedProperty showJoystickAxisSensitivity = setting.FindPropertyRelative("_showJoystickAxisSensitivity");
                    SerializedProperty showMouseXYAxisSensitivity = setting.FindPropertyRelative("_showMouseXYAxisSensitivity");

                    SerializedProperty joystickAxisSensitivityLabelLanguageKey = setting.FindPropertyRelative("_joystickAxisSensitivityLabelLanguageKey");
                    SerializedProperty mouseXYAxisSensitivityLabelLanguageKey = setting.FindPropertyRelative("_mouseXYAxisSensitivityLabelLanguageKey");

                    SerializedProperty joystickAxisSensitivityIcon = setting.FindPropertyRelative("_joystickAxisSensitivityIcon");
                    SerializedProperty mouseXYAxisSensitivityIcon = setting.FindPropertyRelative("_mouseXYAxisSensitivityIcon");

                    SerializedProperty joystickAxisSensitivityMin = setting.FindPropertyRelative("_joystickAxisSensitivityMin");
                    SerializedProperty joystickAxisSensitivityMax = setting.FindPropertyRelative("_joystickAxisSensitivityMax");
                    SerializedProperty mouseXYAxisSensitivityMin = setting.FindPropertyRelative("_mouseXYAxisSensitivityMin");
                    SerializedProperty mouseXYAxisSensitivityMax = setting.FindPropertyRelative("_mouseXYAxisSensitivityMax");

                    EditorGUILayout.PropertyField(labelLanguageKey);
                    
                    EditorGUILayout.PropertyField(showJoystickAxisSensitivity);
                    if(showJoystickAxisSensitivity.boolValue) {
                        EditorGUILayout.PropertyField(joystickAxisSensitivityLabelLanguageKey);
                        EditorGUILayout.PropertyField(joystickAxisSensitivityIcon);
                        DrawFloatProperty(joystickAxisSensitivityMin, 0f, 10000f);
                        DrawFloatProperty(joystickAxisSensitivityMax, 0f, 10000f);
                    }

                    EditorGUILayout.PropertyField(showMouseXYAxisSensitivity);
                    if(showMouseXYAxisSensitivity.boolValue) {
                        EditorGUILayout.PropertyField(mouseXYAxisSensitivityLabelLanguageKey);
                        EditorGUILayout.PropertyField(mouseXYAxisSensitivityIcon);
                        DrawFloatProperty(mouseXYAxisSensitivityMin, 0f, 10000f);
                        DrawFloatProperty(mouseXYAxisSensitivityMax, 0f, 10000f);
                    }
                    
                    EditorGUILayout.Space();

                    // Array control butons
                    GUILayout.Space(20f);
                    using(new EditorGUILayoutSection(false)) {
                        GUILayout.FlexibleSpace();
                        if(GUILayout.Button("Delete", GUILayout.ExpandWidth(false), GUILayout.Width(100f))) {
                            settingsArray.DeleteArrayElementAtIndex(i);
                            break; // exit now to avoid issues
                        }
                    }
                }

                GUILayout.Space(20f);
            }

            EditorGUILayout.Space();
            if(GUILayout.Button("+ Add Input Behavior")) {
                settingsArray.InsertArrayElementAtIndex(settingsArray.arraySize);
                SerializedProperty setting = settingsArray.GetArrayElementAtIndex(settingsArray.arraySize - 1);
                // Clear to defaults
                setting.FindPropertyRelative("_inputBehaviorId").intValue = 0;
                setting.FindPropertyRelative("_labelLanguageKey").stringValue = string.Empty;
                setting.FindPropertyRelative("_showJoystickAxisSensitivity").boolValue = false;
                setting.FindPropertyRelative("_showMouseXYAxisSensitivity").boolValue = false;
                setting.FindPropertyRelative("_joystickAxisSensitivityLabelLanguageKey").stringValue = string.Empty;
                setting.FindPropertyRelative("_mouseXYAxisSensitivityLabelLanguageKey").stringValue = string.Empty;
                setting.FindPropertyRelative("_joystickAxisSensitivityIcon").objectReferenceValue = (Sprite)AssetDatabase.LoadAssetAtPath(AssetDatabase.GUIDToAssetPath("0c9ce4e64fb83764aa394faeeed56210"), typeof(Sprite));
                setting.FindPropertyRelative("_mouseXYAxisSensitivityIcon").objectReferenceValue = (Sprite)AssetDatabase.LoadAssetAtPath(AssetDatabase.GUIDToAssetPath("fc88ce24a47f4014cb0ad237abc8d1dd"), typeof(Sprite));
                setting.FindPropertyRelative("_joystickAxisSensitivityMin").floatValue = 0.0f;
                setting.FindPropertyRelative("_joystickAxisSensitivityMax").floatValue = 2.0f;
                setting.FindPropertyRelative("_mouseXYAxisSensitivityMin").floatValue = 0.0f;
                setting.FindPropertyRelative("_mouseXYAxisSensitivityMax").floatValue = 2.0f;
            }
            EditorGUILayout.Space();
        }
        private void CheckList(UnityEditor.SerializedProperty targets)
        {
            if (targetsList == null)
            {
                targetsList = new UnityEditorInternal.ReorderableList(serializedObject, targets);

                targetsList.drawHeaderCallback = position => EditorGUI.LabelField(position, "Renderers. All renderers that will be included to outline rendering should be in the list.");

                targetsList.drawElementCallback = (position, item, isActive, isFocused) =>
                {
                    var renderPosition = position;
                    var element        = targets.GetArrayElementAtIndex(item);
                    var rendererItem   = element.FindPropertyRelative("Renderer");
                    var reference      = rendererItem.objectReferenceValue;

                    EditorGUI.PropertyField(renderPosition, element, new GUIContent(reference == null ? "Null" : reference.name), true);
                };

                targetsList.elementHeightCallback = (index) => EditorGUI.GetPropertyHeight(targets.GetArrayElementAtIndex(index));

                targetsList.onRemoveCallback = (list) =>
                {
                    var index = list.index;
                    targets.DeleteArrayElementAtIndex(index);
                    targets.serializedObject.ApplyModifiedProperties();
                };

                targetsList.onAddDropdownCallback = (buttonRect, targetList) =>
                {
                    var outlinable = target as Outlinable;
                    var items      = outlinable.gameObject.GetComponentsInChildren <Renderer>(true);
                    var menu       = new GenericMenu();

                    if (!Application.isPlaying)
                    {
                        menu.AddItem(new GUIContent("Add all"), false, () =>
                        {
                            (target as Outlinable).AddAllChildRenderersToRenderingList();

                            EditorUtility.SetDirty(target);
                        });
                    }

                    menu.AddItem(new GUIContent("Empty"), false, () =>
                    {
                        (target as Outlinable).OutlineTargets.Add(new OutlineTarget());

                        EditorUtility.SetDirty(target);
                    });

                    foreach (var item in items)
                    {
                        var found = false;
                        for (var index = 0; index < targets.arraySize; index++)
                        {
                            var element         = targets.GetArrayElementAtIndex(index);
                            var elementRenderer = element.FindPropertyRelative("Renderer");
                            if (elementRenderer.objectReferenceValue == item)
                            {
                                found = true;
                                break;
                            }
                        }

                        var path = string.Empty;
                        if (item.transform != outlinable.transform)
                        {
                            var parent = item.transform;
                            do
                            {
                                path   = string.Format("{0}/{1}", parent.ToString(), path);
                                parent = parent.transform.parent;
                            }while (parent != outlinable.transform);

                            path = string.Format("{0}/{1}", parent.ToString(), path);

                            path = path.Substring(0, path.Length - 1);
                        }
                        else
                        {
                            path = item.ToString();
                        }

                        GenericMenu.MenuFunction function = () =>
                        {
                            var index = targets.arraySize;
                            targets.InsertArrayElementAtIndex(index);
                            var arrayItem = targets.GetArrayElementAtIndex(index);
                            var renderer  = arrayItem.FindPropertyRelative("Renderer");
                            arrayItem.FindPropertyRelative("CutoutThreshold").floatValue = 0.5f;
                            renderer.objectReferenceValue = item;

                            serializedObject.ApplyModifiedProperties();
                        };

                        if (found)
                        {
                            function = null;
                        }

                        menu.AddItem(new GUIContent(path), found, function);
                    }

                    menu.ShowAsContext();
                };
            }
        }
    public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
    {
        label = EditorGUI.BeginProperty(position, label, property);
        property.isExpanded = EditorGUILayout.Foldout( property.isExpanded, label );
        if( property.isExpanded )
        {

            EditorGUI.indentLevel += 1;
            place = property.FindPropertyRelative("UnityPlaces");
            number = property.FindPropertyRelative("Number");
            /*if(place.arraySize == 0){
                place.InsertArrayElementAtIndex(0);
            }*/

            for( int i = 0 ; i < place.arraySize; ++i )
            {
                name = "Place "+(i+1);
                GUILayout.BeginHorizontal();
                EditorGUILayout.PrefixLabel(new GUIContent( name));
                GUILayout.Space(-22);
                EditorGUILayout.PropertyField( place.GetArrayElementAtIndex(i));
                GUILayout.Space(5);
                if( GUILayout.Button ("-", EditorStyles.miniButton, GUILayout.ExpandWidth(false) ) )
                {
                    if(i >= 0){
                        List<GameObject> listDelete = new List<GameObject>();
                        for (int j = 0; j < PlacesNPC.Count; j++)
                        {
                            if (PlacesNPC[j] != null && place.GetArrayElementAtIndex(i).objectReferenceValue != null && PlacesNPC[j].name == place.GetArrayElementAtIndex(i).objectReferenceValue.name)
                                listDelete.Add(PlacesNPC[j]);

                        }
                        for(int j = 0; j < listDelete.Count; j++)
                            GameObject.DestroyImmediate(listDelete[j]);

         						place.GetArrayElementAtIndex(i).objectReferenceValue = null;
                        place.DeleteArrayElementAtIndex(i);
                        //PlacesNPC.RemoveAt(i);

                    }
                    //GUILayout.FlexibleSpace();
                    GUILayout.EndHorizontal();
                    break;
                }

                GUILayout.Space(5);
                //GUILayout.FlexibleSpace();
                GUILayout.EndHorizontal();

            }

            GUILayout.Space(5);
            GUILayout.BeginHorizontal();
            GUILayout.FlexibleSpace();
            if( GUILayout.Button("Generate Place", EditorStyles.miniButtonLeft, GUILayout.ExpandWidth(false), GUILayout.Width(100) ) )
            {
                GeneratePlaces();

            }
            if( GUILayout.Button("Add Existing Place", EditorStyles.miniButtonRight, GUILayout.ExpandWidth(false), GUILayout.Width(125) ) )
            {
                place.InsertArrayElementAtIndex(place.arraySize);
                place.GetArrayElementAtIndex(place.arraySize-1 ).objectReferenceValue = null;
                PlacesNPC.Add(null);
                number.intValue += 1;

            }

            GUILayout.FlexibleSpace();
            GUILayout.EndHorizontal();
            EditorGUI.indentLevel -= 1;

        }
        EditorGUI.EndProperty();
    }
        private bool showVector2IntList(SerializedProperty list, bool foldout)
        {
            int listSize = list.arraySize;
            listSize = EditorGUILayout.IntField("Count", listSize);

            if(listSize != list.arraySize)
            {
                while(listSize > list.arraySize)
                {
                    list.InsertArrayElementAtIndex(list.arraySize);
                }
                while(listSize < list.arraySize)
                {
                    list.DeleteArrayElementAtIndex(list.arraySize - 1);
                }
            }

            if (listSize > 0)
            {
                EditorGUI.indentLevel++;
                foldout = EditorGUILayout.Foldout(foldout, "Point List");
                if (foldout)
                {
                    for(int i = 0; i < list.arraySize; i++)
                    {
                        SerializedProperty element = list.GetArrayElementAtIndex(i);
                        SerializedProperty x = element.FindPropertyRelative("x");
                        SerializedProperty y = element.FindPropertyRelative("y");

                        EditorGUILayout.LabelField("Point " + (i + 1));
                        EditorGUI.indentLevel++;
                        EditorGUILayout.PropertyField(x);
                        EditorGUILayout.PropertyField(y);
                        EditorGUI.indentLevel--;
                    }
                }
                EditorGUI.indentLevel--;
            }

            return foldout;
        }
Example #21
0
 private void DrawNew(SerializedProperty spList)
 {
     // 绘制新增项
     GUILayout.BeginHorizontal();
     EditorGUILayout.LabelField("New Key:", GUILayout.MinWidth(55), GUILayout.MaxWidth(110));
     GUI.changed = false;
     tmpKey = EditorGUILayout.TextField(tmpKey);
     GUILayout.EndHorizontal();
     // 一旦有变动,就要清除ErrorCode,这样可以保证出错后修改能立马清除错误
     if (GUI.changed) tmpErrorCode = 0;
     Event curEvent = Event.current;
     // Enter弹起时进行校验
     if (curEvent.type == EventType.KeyUp && (curEvent.keyCode == KeyCode.Return ||
         curEvent.keyCode == KeyCode.KeypadEnter))
     {
         if (string.IsNullOrEmpty(tmpKey) || tmpKey.Length > 40)
         {
             // 长度不合法
             tmpErrorCode = 1;
         }
         else if (ContainsKey(spList, tmpKey))
         {
             // 名称已存在
             tmpErrorCode = 2;
         }
         else
         {
             // 添加新项
             int index = spList.arraySize;
             spList.InsertArrayElementAtIndex(index);
             SerializedProperty spNewEntity = spList.GetArrayElementAtIndex(index);
             SerializedProperty spNewEntityKey = spNewEntity.FindPropertyRelative("key");
             spNewEntityKey.stringValue = tmpKey;
             // 恢复
             tmpKey = string.Empty;
             tmpErrorCode = 0;
         }
         // 切记要调用
         curEvent.Use();
     }
     switch (tmpErrorCode)
     {
         case 1:
             EditorGUILayout.HelpBox("Key Can Not Be Empty!But Less Than 40 Yet!", MessageType.Error);
             break;
         case 2:
             EditorGUILayout.HelpBox("Same Key Has Exist!", MessageType.Error);
             break;
     }
 }
Example #22
0
    public void ChangeColorCount(SerializedProperty _list, int _from, int _to)
    {
        if (_to < 1 || _to > 100)
        {
            return;
        }
        int cnt = Mathf.Abs(_to - _from);
        if (_to > _from)
        {
            // add
            for (int i = 0; i < m_item_count; i++)
            {
                for (int c = 0; c < cnt; c++)
                {
                    _list.InsertArrayElementAtIndex(m_item_count * m_color_count - i * m_color_count);
                }
            }
        }
        else
        {
            // remove
            for (int i = 0; i < m_item_count; i++)
            {
                for (int c = 0; c < cnt; c++)
                {
                    _list.DeleteArrayElementAtIndex(m_item_count * m_color_count - cnt - i * m_color_count);
                }
            }
        }

        m_target.ApplyModifiedProperties();
        if (m_type == PACKAGE_TYPE.ARMOR)
        {
            m_scrypt.UpdateList(_to);
        }
    }
        void ShowClosestPointOnOpenSpline(SerializedProperty points)
        {
            var   spline = target as SplineComponent;
            var   plane  = new Plane(spline.transform.up, spline.transform.position);
            var   ray    = HandleUtility.GUIPointToWorldRay(Event.current.mousePosition);
            float center;

            if (plane.Raycast(ray, out center))
            {
                var hit      = ray.origin + ray.direction * center;
                var discSize = HandleUtility.GetHandleSize(hit);
                Handles.DrawWireDisc(hit, spline.transform.up, discSize);
                var p = SearchForClosestPoint(Event.current.mousePosition);


                if ((hit - spline.GetNonUniformPoint(0)).sqrMagnitude < 25)
                {
                    p = 0;
                }
                if ((hit - spline.GetNonUniformPoint(1)).sqrMagnitude < 25)
                {
                    p = 1;
                }


                var sp = spline.GetNonUniformPoint(p);


                var extend = Mathf.Approximately(p, 0) || Mathf.Approximately(p, 1);


                Handles.color = extend ? Color.red : Color.white;
                Handles.DrawLine(hit, sp);
                Handles.color = Color.white;


                var i = 1 + Mathf.FloorToInt(p * (spline.points.Count - 3));


                if (Event.current.type == EventType.MouseDown && Event.current.button == 0 && Event.current.shift)
                {
                    if (extend)
                    {
                        if (i == spline.points.Count - 2)
                        {
                            i++;
                        }
                        points.InsertArrayElementAtIndex(i);
                        points.GetArrayElementAtIndex(i).vector3Value = spline.transform.InverseTransformPoint(hit);
                        hotIndex = i;
                    }
                    else
                    {
                        i++;
                        points.InsertArrayElementAtIndex(i);
                        points.GetArrayElementAtIndex(i).vector3Value = spline.transform.InverseTransformPoint(sp);
                        hotIndex = i;
                    }
                    serializedObject.ApplyModifiedProperties();
                }
            }
        }
Example #24
0
    void AddObjectDropZone(SerializedProperty gos)
    {
        Event e = Event.current;

        Rect dropArea = GUILayoutUtility.GetRect(0, 25, GUILayout.ExpandWidth(true));
        GUI.Box(dropArea, "Drag game objects here");

        switch (e.type)
        {
        case EventType.DragUpdated:
        case EventType.DragPerform:
            if(!dropArea.Contains(e.mousePosition))
                break;

            DragAndDrop.visualMode = DragAndDropVisualMode.Copy;

            if(e.type == EventType.DragPerform)
            {
                foreach (var item in DragAndDrop.objectReferences)
                {
                    if(item is GameObject)
                    {
                        var newgo = item as GameObject;
                        int index = gos.arraySize;
                        gos.InsertArrayElementAtIndex(index);
                        gos.GetArrayElementAtIndex(index).FindPropertyRelative("GO").objectReferenceValue = newgo;
                    }
                }
            }

            e.Use();
            break;
        }
    }
        private void DrawEditableSerializedPropertyArray(SerializedProperty serializedPropertyArray, string label, int[] values, string[] names) {
            if(serializedPropertyArray == null || !serializedPropertyArray.isArray) return;

            for(int i = 0; i < serializedPropertyArray.arraySize; i++) {
                SerializedProperty prop = serializedPropertyArray.GetArrayElementAtIndex(i);

                using(new EditorGUILayoutSection(false)) {
                    DrawPopupProperty(new GUIContent(label + " " + i), values, names, prop);
                    GUILayout.Space(10f);
                    if(GUILayout.Button("Del", GUILayout.Width(50f))) {
                        serializedPropertyArray.DeleteArrayElementAtIndex(i);
                    }
                }
            }

            EditorGUILayout.Space();
            if(GUILayout.Button("Add " + label)) { // insert new one at end
                serializedPropertyArray.InsertArrayElementAtIndex(serializedPropertyArray.arraySize);
            }
        }
 static void CopyArrayToSerialized( SerializedProperty dest, GameObject[] sources )
 {
     if( dest.arraySize != sources.Length )
     {
         dest.ClearArray();
         for( int i = 0; i < sources.Length; ++i )
         {
             dest.InsertArrayElementAtIndex( i );
         }
     }
     for( int i = 0; i < sources.Length; ++i )
     {
         if( dest.GetArrayElementAtIndex( i ).objectReferenceValue != sources[i] )
             dest.GetArrayElementAtIndex( i ).objectReferenceValue = sources[i];
     }
 }
Example #27
0
 protected void ArrayList(SerializedProperty property, string title, Runnable1<SerializedProperty> renderer) {
     if (Foldout(title, false)) {
         Indent(() => {
             if (property.arraySize == 0) {
                 GUILayout.Label("   Use 'Add' button to add items");
             } else {
                 int arrSize = property.arraySize;
                 Separator();
                 for (int i = 0; i < arrSize; ++i) {
                     var go = property.GetArrayElementAtIndex(i);
                     EditorGUILayout.BeginHorizontal();
                     
                     EditorGUILayout.BeginVertical();
                     renderer(go);
                     EditorGUILayout.EndVertical();
                     
                     GUI.color = Color.red;
                     if (GUILayout.Button("X", GUILayout.ExpandWidth(false))) {
                         property.DeleteArrayElementAtIndex(i);
                         arrSize--;
                     }
                     GUI.color = Color.white;
                     EditorGUILayout.EndHorizontal();
                     
                     if (i + 1 < arrSize) {
                         EditorGUILayout.Space();
                     }
                     Separator();
                 }
             }
             
             GUI.color = Color.green;
             EditorGUILayout.BeginHorizontal();
             GUILayout.FlexibleSpace();
             if (GUILayout.Button("Add", GUILayout.ExpandWidth(false))) {
                 property.InsertArrayElementAtIndex(property.arraySize);
   
                 // when creating new array element like this, the color will be initialized with
                 // (0, 0, 0, 0) - zero aplha. This may be confusing for end user so this workaround looks
                 // for color fields and sets them to proper values                  
                 var element = property.GetArrayElementAtIndex(property.arraySize - 1);                  
                 var enumerator = element.GetEnumerator();
                 while (enumerator.MoveNext()) {
                     var el = enumerator.Current as SerializedProperty;
                     if (el.type == "ColorRGBA") {
                         el.colorValue = Color.white;
                     }
                 }
             }
             GUI.color = Color.white;
             EditorGUILayout.EndHorizontal();
         });
     }
 }
 private void DoApply(SerializedObject so)
 {
     if (this.multipleSprites)
     {
         List <string>      list  = new List <string>();
         List <string>      list2 = new List <string>();
         SerializedProperty serializedProperty = so.FindProperty("m_SpriteSheet.m_Sprites");
         for (int i = 0; i < this.m_RectsCache.Count; i++)
         {
             SpriteRect spriteRect = this.m_RectsCache.RectAt(i);
             if (string.IsNullOrEmpty(spriteRect.name))
             {
                 spriteRect.name = "Empty";
             }
             if (!string.IsNullOrEmpty(spriteRect.originalName))
             {
                 list.Add(spriteRect.originalName);
                 list2.Add(spriteRect.name);
             }
             if (serializedProperty.arraySize < this.m_RectsCache.Count)
             {
                 serializedProperty.InsertArrayElementAtIndex(serializedProperty.arraySize);
             }
             SerializedProperty arrayElementAtIndex = serializedProperty.GetArrayElementAtIndex(i);
             spriteRect.ApplyToSerializedProperty(arrayElementAtIndex);
             EditorUtility.DisplayProgressBar(SpriteEditorWindow.SpriteEditorWindowStyles.saveProgressTitle.text, string.Format(SpriteEditorWindow.SpriteEditorWindowStyles.saveContentText.text, i, this.m_RectsCache.Count), (float)i / (float)this.m_RectsCache.Count);
         }
         while (this.m_RectsCache.Count < serializedProperty.arraySize)
         {
             serializedProperty.DeleteArrayElementAtIndex(this.m_RectsCache.Count);
         }
         if (list.Count > 0)
         {
             PatchImportSettingRecycleID.PatchMultiple(so, 213, list.ToArray(), list2.ToArray());
         }
     }
     else if (this.m_RectsCache.Count > 0)
     {
         SpriteRect spriteRect2 = this.m_RectsCache.RectAt(0);
         so.FindProperty("m_Alignment").intValue                  = (int)spriteRect2.alignment;
         so.FindProperty("m_SpriteBorder").vector4Value           = spriteRect2.border;
         so.FindProperty("m_SpritePivot").vector2Value            = spriteRect2.pivot;
         so.FindProperty("m_SpriteTessellationDetail").floatValue = spriteRect2.tessellationDetail;
         SerializedProperty serializedProperty2 = so.FindProperty("m_SpriteSheet.m_Outline");
         if (spriteRect2.outline != null)
         {
             SpriteRect.ApplyOutlineChanges(serializedProperty2, spriteRect2.outline);
         }
         else
         {
             serializedProperty2.ClearArray();
         }
         SerializedProperty serializedProperty3 = so.FindProperty("m_SpriteSheet.m_PhysicsShape");
         if (spriteRect2.physicsShape != null)
         {
             SpriteRect.ApplyOutlineChanges(serializedProperty3, spriteRect2.physicsShape);
         }
         else
         {
             serializedProperty3.ClearArray();
         }
     }
     EditorUtility.ClearProgressBar();
 }
        //private static Color _oldColor;
        private static bool ShowButtons(Rect position, SerializedProperty property, int index)
        {
            var result = false;

            var pos = new Rect(position);
            pos.y += 4;

            if (GUI.Button(pos, GuiContentCache.Instance.EditSelector, StyleCache.Instance.ImageOnlyNoFrameButton)) // EditorStyles.miniButtonMid
            {
                //EditorUtility.DisplayDialog("Editing selector", "Not implemented.", "Close");
                SerializedProperty declaration = property.GetArrayElementAtIndex(index);
                EditStyleDeclarationCommand.Execute(declaration);
            }

            pos.x += ButtonWidth;
            if (GUI.Button(pos, GuiContentCache.Instance.Duplicate, StyleCache.Instance.ImageOnlyNoFrameButton)) // EditorStyles.miniButtonMid
            {
                bool expanded = property.GetArrayElementAtIndex(index).isExpanded;
                property.InsertArrayElementAtIndex(index);
                SerializedProperty newItem = property.GetArrayElementAtIndex(index);
                newItem.Reset();
                newItem.isExpanded = expanded;
            }
            
            pos.x += ButtonWidth;
            if (GUI.Button(pos, GuiContentCache.Instance.Delete, StyleCache.Instance.ImageOnlyNoFrameButton)) // EditorStyles.miniButtonRight
            {
                if (EditorUtility.DisplayDialog("Confirmation", "Are you sure you want to remove this style declaration?", "OK", "Cancel"))
                    result = true;
            }

            // move buttons

            if (index == 0)
                GUI.enabled = false;

            pos.x += ButtonWidth;
            if (GUI.Button(pos, GuiContentCache.Instance.MoveUp, StyleCache.Instance.ImageOnlyNoFrameButton)) // EditorStyles.miniButtonLeft
            {
                if (index > 0)
                {
                    bool expanded1 = property.GetArrayElementAtIndex(index).isExpanded;
                    bool expanded2 = property.GetArrayElementAtIndex(index - 1).isExpanded;
                    property.MoveArrayElement(index, index - 1);
                    property.GetArrayElementAtIndex(index).isExpanded = expanded1;
                    property.GetArrayElementAtIndex(index - 1).isExpanded = expanded2;

                    ShouldProcessStyles = true;
                }
            }
            pos.x += ButtonWidth;

            if (index == 0)
                GUI.enabled = true;

            if (index == _size - 1)
                GUI.enabled = false;

            if (GUI.Button(pos, GuiContentCache.Instance.MoveDown, StyleCache.Instance.ImageOnlyNoFrameButton)) // EditorStyles.miniButtonLeft
            {
                bool expanded1 = property.GetArrayElementAtIndex(index).isExpanded;
                bool expanded2 = property.GetArrayElementAtIndex(index + 1).isExpanded;
                property.MoveArrayElement(index, index + 1);
                property.GetArrayElementAtIndex(index).isExpanded = expanded1;
                property.GetArrayElementAtIndex(index + 1).isExpanded = expanded2;

                ShouldProcessStyles = true;
            }

            if (index == _size - 1)
                GUI.enabled = true;

            pos.x += ButtonWidth;

            return result;
        }
    /// <summary>
    /// <para>該当するアセットを複数検索して描画する</para>
    /// </summary>
    /// <param name='position'>
    /// Position.
    /// </param>
    /// <param name='property'>
    /// Property.
    /// </param>
    /// <param name='label'>
    /// Label.
    /// </param>
    void DrawArrayProperty(Rect position, SerializedProperty property, GUIContent label)
    {
        int size = 0;

        EditorGUI.indentLevel = 2;

        if (labelSearchAttribute.foldout)
        {
            position.y += CONTENT_HEIGHT;
            EditorGUI.LabelField(position, "Size", property.arraySize.ToString());
        }

        property.arraySize = 0;
        property.InsertArrayElementAtIndex(0);
        System.Type type = GetType(property.GetArrayElementAtIndex(0));

        foreach (string path in GetAllAssetPath())
        {
            System.Type assetType = null;
            Object asset = null;

            if (LabelSearchAttribute.assetTypes.TryGetValue(path, out assetType) == false)
            {
                asset = AssetDatabase.LoadMainAssetAtPath(path);
                assetType = asset.GetType();
                LabelSearchAttribute.assetTypes.Add(path, assetType);
            }

            if (type != assetType)
            {
                continue;
            }

            if (asset == null)
            {
                asset = AssetDatabase.LoadMainAssetAtPath(path);
            }

            if (
                string.IsNullOrEmpty(
                    AssetDatabase.GetLabels(asset).FirstOrDefault(l => l.Equals(labelSearchAttribute.labelName))) ==
                false)
            {
                property.arraySize = ++size;
                property.GetArrayElementAtIndex(size - 1).objectReferenceValue = asset;

                if (labelSearchAttribute.foldout)
                {
                    position.y += CONTENT_HEIGHT;
                    position.height = CONTENT_HEIGHT;
                    GUIContent content =
                        EditorGUIUtility.ObjectContent(property.GetArrayElementAtIndex(size - 1).objectReferenceValue,
                            type);
                    content.image = AssetPreview.GetMiniTypeThumbnail(type);
                    // 要素1つ1つにフォーカスが当たらないためObjectFieldである必要はないのでLabelFieldで描画
                    // PingObjectの機能使いたいけど...
                    // EditorGUI.ObjectField (position, new GUIContent (ObjectNames.NicifyVariableName ("Element" + i)), property.GetArrayElementAtIndex (i).objectReferenceValue, type, false);
                    EditorGUI.LabelField(position,
                        new GUIContent(ObjectNames.NicifyVariableName("Element" + (size - 1))), content);
                }
            }

            if (labelSearchAttribute.limit <= property.arraySize)
            {
                break;
            }
        }
    }
Example #31
0
	/*
	 * 
	 * Handle the Part that is responsible for adding and removing additional elements
	 * 
	 * 
	 */

	private static void ShowButtons (SerializedProperty list, int index) {
		/*
		 * 
		 * If a new element will be added to the array of gameobjects
		 * 
		 */
		if (GUILayout.Button(duplicateButtonContent, EditorStyles.miniButtonMid, miniButtonWidth)) {
			list.InsertArrayElementAtIndex(index);
		}
		/*
		 * 
		 * An element will be removed from the array of gameobjects
		 * 
		 */
		if (GUILayout.Button(deleteButtonContent, EditorStyles.miniButtonRight, miniButtonWidth)) {
			int oldSize = list.arraySize;
			list.DeleteArrayElementAtIndex(index);
			//reset the array size
			if (list.arraySize == oldSize) {
				list.DeleteArrayElementAtIndex(index);
			}
		}
	}
		public static void Draw (SerializedProperty _arrayProperty, GUIContent _label, eArrayOptions _options)
		{
			bool _showNameWithFoldout	= (_options & eArrayOptions.SHOW_NAME_WITH_FOLDOUT) != 0;
			bool _showArraySize			= (_options & eArrayOptions.SHOW_ARRAY_SIZE) != 0;
			int _count					= _arrayProperty.arraySize;
			int _originalIndentLevel	= EditorGUI.indentLevel;

			// GUI styles
			GUIStyle _buttonStyle		= EditorStyles.miniButton;
			
			// Show array name
			if (_showNameWithFoldout)
			{
				_arrayProperty.isExpanded = EditorGUILayout.Foldout(_arrayProperty.isExpanded, _label);

				// Update indentation
				EditorGUI.indentLevel++;
			}
			else
			{
				EditorGUILayout.LabelField(_label);
			}

			// Is foldout enabled, then dont show the rest of the elements
			if (!_arrayProperty.isExpanded)
			{
				// Reset indentation to original value
				EditorGUI.indentLevel	= _originalIndentLevel;
				return;
			}

			// Show array size
			if (_showArraySize && _count != 0)
			{
				// Check if size value changes
				EditorGUI.BeginChangeCheck();
				int _newSize		= EditorGUILayout.IntField("Size", _count);
				
				if (EditorGUI.EndChangeCheck())
					_arrayProperty.arraySize	= _newSize;
			}
			
			// If there are no elements then return size of add button
			if (_count == 0)
			{
				if (GUILayout.Button("Add new product", GUILayout.Height(kButtonHeight)))
					_arrayProperty.InsertArrayElementAtIndex(0);
			}
			else
			{
				// Show array elements if it is expanded
				GUIStyle _subviewStyle		= new GUIStyle("ProgressBarBack");

				if (_arrayProperty.isExpanded) 
				{
					for (int _iter = 0; _iter < _count; _iter++) 
					{
						GUILayout.BeginVertical(GUIContent.none, _subviewStyle);
						{
							// Show each element
							EditorGUILayout.PropertyField(_arrayProperty.GetArrayElementAtIndex(_iter));
							
							// Show buttons 
							GUILayout.BeginHorizontal();
							{
								GUILayout.FlexibleSpace();
								
								if (GUILayout.Button("+", _buttonStyle, GUILayout.MinWidth(40)))
								{
									_arrayProperty.InsertArrayElementAtIndex(_iter);
									break;
								}
								
								if (GUILayout.Button("-", _buttonStyle, GUILayout.MinWidth(40)))
								{
									_arrayProperty.DeleteArrayElementAtIndex(_iter);
									break;
								}
							}
							GUILayout.EndHorizontal();
						}
						GUILayout.EndVertical();
					}
				}
			}

			// Reset indentation to original value
			EditorGUI.indentLevel	= _originalIndentLevel;
		}
 private static void ApplyOutlineChanges(SerializedProperty outlineSP, SpriteRect spriteRect)
 {
   outlineSP.ClearArray();
   for (int index1 = 0; index1 < spriteRect.m_Outline.Count; ++index1)
   {
     outlineSP.InsertArrayElementAtIndex(index1);
     SerializedProperty arrayElementAtIndex = outlineSP.GetArrayElementAtIndex(index1);
     arrayElementAtIndex.ClearArray();
     List<Vector2> vector2List = spriteRect.m_Outline[index1];
     for (int index2 = 0; index2 < vector2List.Count; ++index2)
     {
       arrayElementAtIndex.InsertArrayElementAtIndex(index2);
       arrayElementAtIndex.GetArrayElementAtIndex(index2).vector2Value = vector2List[index2];
     }
   }
 }
        private void DrawMappingSet(SerializedProperty mapSetsArray) {
            if(mapSetsArray == null || !mapSetsArray.isArray) return;

            int[] mapCategoryIds = userData.GetMapCategoryIds();
            string[] mapCategoryNames = userData.GetMapCategoryNames();
            int[] actionCategoryIds = userData.GetActionCategoryIds();
            string[] actionCategoryNames = userData.GetActionCategoryNames();
            int[] actionIds = userData.GetActionIds();
            string[] actionNames = userData.GetActionNames();

            EditorGUILayout.Space();

            EditorGUILayout.HelpBox(
                "You can define a list of Map Categories to be shown to the user for remapping.\n\n" +
                "You can choose to show one or multiple Map Categories. If you define multiple Map Categories here, " +
                "a new row of buttons will be shown that will allow the user to select a Map Category for which to create input assignments. " +
                "You must define a list of assignable Actions to displayed to the user for each Map Category. You can choose to show the user a list of all user-assignable Actions " +
                "contained in an one or more Action Categories or a customized list of individual Actions."
            , MessageType.Info);

            EditorGUILayout.Space();

            int count = mapSetsArray.arraySize;
            if(count == 0) {
                EditorGUILayout.HelpBox("You must have at least one map category!", MessageType.Error);
            }
            for(int i = 0; i < count; i++) {

                using(new EditorGUILayoutSection(true, style_mapSetBkg)) {

                    SerializedProperty mapSet = mapSetsArray.GetArrayElementAtIndex(i);

                    GUILayout.Space(20f);
                    SerializedProperty mapCategoryId = mapSet.FindPropertyRelative("_mapCategoryId");
                    DrawPopupProperty(new GUIContent("Map Category", "The Map Category that will be displayed to the user for mapping."), mapCategoryIds, mapCategoryNames, mapCategoryId); // NOTE: mapCategoryId tool tip from Attribute is always NULL!
                    int selectedMapCategoryIndex = System.Array.IndexOf<int>(mapCategoryIds, mapCategoryId.intValue);
                    if(selectedMapCategoryIndex < 0) continue;

                    SerializedProperty actionListMode = mapSet.FindPropertyRelative("_actionListMode");
                    EditorGUILayout.PropertyField(actionListMode);

                    EditorGUILayout.Space();

                    if((ControlMapper.MappingSet.ActionListMode)actionListMode.intValue == ControlMapper.MappingSet.ActionListMode.ActionCategory) {

                        EditorGUILayout.LabelField(new GUIContent("Action Categories:", "List each Action Category you want to be displayed for this map category. This will list all user-assignable Actions in that category allowing the user to make assignments for each of these Actions."));
                        EditorGUILayout.Space();

                        SerializedProperty actionCategoryIdsArray = mapSet.FindPropertyRelative("_actionCategoryIds");
                        DrawEditableSerializedPropertyArray(actionCategoryIdsArray, "Action Category", actionCategoryIds, actionCategoryNames);

                    } else {

                        EditorGUILayout.LabelField(new GUIContent("Actions:", "List each Action you want to be displayed for this map category. This will allow the user to make assignments for each of these Actions."));
                        EditorGUILayout.Space();

                        SerializedProperty actionIdsArray = mapSet.FindPropertyRelative("_actionIds");
                        DrawEditableSerializedPropertyArray(actionIdsArray, "Action", actionIds, actionNames);
                    }

                    // Array control butons
                    GUILayout.Space(20f);
                    using(new EditorGUILayoutSection(false)) {
                        GUILayout.FlexibleSpace();
                        bool guiEnabled = GUI.enabled;
                        if(i == 0) GUI.enabled = false; // don't allow deleting the first entry
                        if(GUILayout.Button("Delete", GUILayout.ExpandWidth(false), GUILayout.Width(100f))) {
                            mapSetsArray.DeleteArrayElementAtIndex(i);
                            break; // exit now to avoid issues
                        }
                        if(i == 0) GUI.enabled = guiEnabled;
                    }
                }

                GUILayout.Space(20f);
            }

            EditorGUILayout.Space();
            if(GUILayout.Button("+ Add Map Category")) {
                mapSetsArray.InsertArrayElementAtIndex(mapSetsArray.arraySize);
            }
            EditorGUILayout.Space();
        }
	private void AddReference(SerializedProperty dataProperty, string key, UnityEngine.Object obj)
	{
		int index = dataProperty.arraySize;
		dataProperty.InsertArrayElementAtIndex(index);
		var element = dataProperty.GetArrayElementAtIndex(index);
		element.FindPropertyRelative("key").stringValue = key;
		element.FindPropertyRelative("gameObject").objectReferenceValue = obj;
	}
Example #36
0
        private static void AddNewArrayElement(SerializedProperty _list, int _index)
        {
            _list.InsertArrayElementAtIndex(_index);

            SerializedProperty item = _list.GetArrayElementAtIndex((_index + 1) % _list.arraySize);

            SerializedProperty name = item.FindPropertyRelative("name");
            name.stringValue = string.Concat("Layer ", _list.arraySize.ToString());

            if (item.FindPropertyRelative("lightLayerMask") != null)
                item.FindPropertyRelative("lightLayerMask").intValue = 1;

            if (item.FindPropertyRelative("lightIntensity") != null)
                item.FindPropertyRelative("lightIntensity").floatValue = 1;

            if(item.FindPropertyRelative("ambientColor") != null)
                item.FindPropertyRelative("ambientColor").colorValue = new Color(0.2f, 0.2f, 0.235f, 1f);

            if (item.FindPropertyRelative("clearFlag") != null)
                item.FindPropertyRelative("clearFlag").intValue = (int)CameraClearFlags.Color;

            if (item.FindPropertyRelative("backgroundColor") != null)
                item.FindPropertyRelative("backgroundColor").colorValue = new Color(0.5f, 0.5f, 0.5f, 0f);

            if (item.FindPropertyRelative("lightsEnabled") != null)
                item.FindPropertyRelative("lightsEnabled").boolValue = true;
        }