예제 #1
0
        public override void OnGUI(UnityEngine.Rect position, SerializedProperty property, UnityEngine.GUIContent label)
        {
            ReorderableListAttribute attr = attribute as ReorderableListAttribute;
            string tooltip = (attr == null ? string.Empty : attr.Tooltip);

            UnityEditorInternal.ReorderableList list = GetList(property);
            float height;

            if (list.serializedProperty.arraySize == 0)
            {
                height = 20.0f;
            }
            else
            {
                height = 0.0f;
                for (var i = 0; i < list.serializedProperty.arraySize; i++)
                {
                    height = Mathf.Max(height, EditorGUI.GetPropertyHeight(list.serializedProperty.GetArrayElementAtIndex(i)));
                }
            }
            list.drawHeaderCallback = (Rect r) =>
            {
                EditorGUI.LabelField(r, new GUIContent(label.text, tooltip));
            };
            list.elementHeight = height;
            list.DoList(position);
        }
 public void DoList(Rect position)
 {
     if (IsValid())
     {
         ListDrawer.DoList(position);
     }
 }
예제 #3
0
        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            if (!Initialize(property))
            {
                EditorGUI.HelpBox(position, "Unable to use 'ReorderableList' for " + property.name, MessageType.Error);
                return;
            }

            List.DoList(position);
        }
예제 #4
0
        public static Rect DrawReorderableList(Rect position, UnityEditorInternal.ReorderableList sentList, string label = null)
        {
            //draw label
            Rect newPosition = position;

            if (!string.IsNullOrEmpty(label))
            {
                newPosition = GetPosition(newPosition, LineHeight);
                EditorGUI.LabelField(newPosition, label, EditorStyles.boldLabel);
            }
            //draw list
            newPosition = GetPosition(newPosition, sentList.GetHeight());
            Rect listPosition = GetListPosition(newPosition);

            sentList.DoList(listPosition);
            sentList.draggable = true;
            return(newPosition);
        }
        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            SerializedProperty listProperty = property.FindPropertyRelative("_items");

            if (null == _reorderableList)
            {
                Initialize(property, listProperty, new GUIContent(label.text));
            }

            float elementHeight = 0.0f;

            for (int i = 0; i < listProperty.arraySize; ++i)
            {
                elementHeight = Mathf.Max(elementHeight, EditorGUI.GetPropertyHeight(listProperty.GetArrayElementAtIndex(i)));
            }
            _reorderableList.elementHeight = elementHeight;

            _reorderableList.DoList(position);
        }
예제 #6
0
        protected override void DrawContent()
        {
            ProxyList.Resize(Node.Inputs.Count);

            drawRect.x     += 2;
            drawRect.width -= 4;

            EditorGUI.BeginChangeCheck();
            {
                var old_rect = drawRect;

                drawRect.y    += 2;
                drawRect.width = drawRect.width - 20;

                //drawRect.y += 20;
                drawRect.height = VariantUtils.FieldHeight;
                string content = Node.InputType.ToString();
                if (GUI.Button(drawRect, content, EditorStyles.objectField))
                {
                    KnownTypeUtils.ShowAddParameterMenu(OnTypeChanged);
                }

                drawRect.x     = old_rect.x;
                drawRect.width = old_rect.width;

                drawRect.y     += VariantUtils.FieldHeight + 4;
                drawRect.height = old_rect.height - drawRect.y;

                var base_y = drawRect.y - old_rect.y + BOTTOM_MARGIN;
                if (DrawerList != null)
                {
                    DrawerList.DoList(drawRect);
                    Size = new Vector2(Size.x, base_y + DrawerList.GetHeight() + 8);
                }
            }
            if (EditorGUI.EndChangeCheck())
            {
                AssetDatabase.SaveAssets();
            }
        }
예제 #7
0
        /// <summary> Panel to show "Clip" options of Sequence </summary>
        /// <param name="inlineHelp">Should help be displayed?</param>
        public void ClipsPanel(bool inlineHelp)
        {
            ++EditorGUI.indentLevel;
            EditorGUI.BeginChangeCheck();
            Rect clipsRect;

            if (m_clipsExpanded)
            {
                clipsRect = EditorGUILayout.GetControlRect(true, m_clipsReorderable.GetHeight());
                m_clipsReorderable.DoList(clipsRect);
            }
            else
            {
                int oldIndent = EditorGUI.indentLevel;
                EditorGUI.indentLevel = 1;
                m_clipsExpanded       = EditorGUILayout.Foldout(m_clipsExpanded, PropertyCount("mClips", m_clipData), true);
                clipsRect             = GUILayoutUtility.GetLastRect();
                EditorGUI.indentLevel = oldIndent;
            }
            if (Event.current.type == EventType.DragUpdated && clipsRect.Contains(Event.current.mousePosition))
            {
                bool isValid = false;
                for (int i = 0; i < DragAndDrop.objectReferences.Length; ++i)
                {
                    if (DragAndDrop.objectReferences[i] is AudioClip)
                    {
                        isValid = true;
                        break;
                    }
                }
                if (isValid)
                {
                    DragAndDrop.visualMode = DragAndDropVisualMode.Link;
                }
                else
                {
                    DragAndDrop.visualMode = DragAndDropVisualMode.Rejected;
                }
            }
            else if (Event.current.type == EventType.DragPerform && clipsRect.Contains(Event.current.mousePosition))
            {
                for (int i = 0; i < DragAndDrop.objectReferences.Length; ++i)
                {
                    if (!(DragAndDrop.objectReferences[i] is AudioClip))
                    {
                        continue;
                    }
                    int idx = m_clipData.arraySize;
                    m_clipData.InsertArrayElementAtIndex(idx);
                    SerializedProperty clipData = m_clipData.GetArrayElementAtIndex(idx);
                    clipData.FindPropertyRelative("m_volume").floatValue         = 1f;
                    clipData.FindPropertyRelative("m_clip").objectReferenceValue = DragAndDrop.objectReferences[i];
                }
                Event.current.Use();
            }

            m_editorUtils.InlineHelp("mClips", inlineHelp);
            //PropertyCountField("mClips", true, m_clips, ((Sequence)target).m_clips.Length, inlineHelp);
            int badClipCount = 0;

            for (int x = 0; x < m_clipData.arraySize; ++x)
            {
                AudioClip clip = m_clipData.GetArrayElementAtIndex(x).FindPropertyRelative("m_clip").objectReferenceValue as AudioClip;
                if (clip != null)
                {
                    if (clip.loadType != AudioClipLoadType.DecompressOnLoad)
                    {
                        ++badClipCount;
                    }
                }
            }
            if (badClipCount > 0)
            {
                EditorGUILayout.HelpBox(m_editorUtils.GetContent("InvalidClipMessage").text, MessageType.Warning, true);
                if (m_editorUtils.ButtonRight("InvalidClipButton"))
                {
                    GUIContent progressBarContent = m_editorUtils.GetContent("InvalidClipPopup");
                    for (int x = 0; x < m_clipData.arraySize; ++x)
                    {
                        AudioClip clip = m_clipData.GetArrayElementAtIndex(x).FindPropertyRelative("m_clip").objectReferenceValue as AudioClip;
                        EditorUtility.DisplayProgressBar(progressBarContent.text, progressBarContent.tooltip + clip.name, x / (float)badClipCount);
                        if (clip != null)
                        {
                            if (clip.loadType != AudioClipLoadType.DecompressOnLoad)
                            {
                                AudioImporter importer = AssetImporter.GetAtPath(AssetDatabase.GetAssetPath(clip)) as AudioImporter;
                                AudioImporterSampleSettings sampleSettings = importer.defaultSampleSettings;
                                sampleSettings.loadType        = AudioClipLoadType.DecompressOnLoad;
                                importer.defaultSampleSettings = sampleSettings;
                                if (importer.ContainsSampleSettingsOverride("Standalone"))
                                {
                                    sampleSettings          = importer.GetOverrideSampleSettings("Standalone");
                                    sampleSettings.loadType = AudioClipLoadType.DecompressOnLoad;
                                    importer.SetOverrideSampleSettings("Standalone", sampleSettings);
                                }
                                importer.SaveAndReimport();
                            }
                        }
                    }
                    EditorUtility.ClearProgressBar();
                }
            }
            if (EditorGUI.EndChangeCheck() && Application.isPlaying)
            {
                (target as Sequence).UpdateModifiers();
            }
            m_editorUtils.PropertyField("mTrackFadeTime", m_trackFadeTime, inlineHelp);
            if (m_trackFadeTime.floatValue < 0f)
            {
                m_trackFadeTime.floatValue = 0f;
            }
            m_editorUtils.PropertyField("mVolume", m_volume, inlineHelp);
            m_editorUtils.PropertyField("mVolumeFadeTime", m_volumeFadeTime, inlineHelp);
            if (m_volumeFadeTime.floatValue < 0f)
            {
                m_volumeFadeTime.floatValue = 0f;
            }
            EditorGUI.BeginDisabledGroup(syncGroup.target && ((SyncType)System.Enum.GetValues(typeof(SyncType)).GetValue(m_syncType.enumValueIndex) & SyncType.FIT) > 0); {
                m_editorUtils.PropertyField("mPlaybackSpeed", m_playbackSpeed, inlineHelp);
                if (m_playbackSpeed.floatValue < 0f)
                {
                    m_playbackSpeed.floatValue = 0f;
                }
            } EditorGUI.EndDisabledGroup();
            EditorGUI.BeginDisabledGroup(syncGroup.target); {
                m_editorUtils.PropertyField("mPlaybackSpeedFadeTime", m_playbackSpeedFadeTime, inlineHelp);
                if (m_playbackSpeedFadeTime.floatValue < 0f)
                {
                    m_playbackSpeedFadeTime.floatValue = 0f;
                }
                m_editorUtils.PropertyField("mCrossFade", m_crossFade, inlineHelp);
                if (m_crossFade.floatValue < 0f)
                {
                    m_crossFade.floatValue = 0f;
                }
            } EditorGUI.EndDisabledGroup();
            --EditorGUI.indentLevel;
        }
예제 #8
0
        private void OnGUI()
        {
            serializerCollectionPath   = EditorGUILayout.TextField("SerializerCollection path", serializerCollectionPath);
            deserializerCollectionPath = EditorGUILayout.TextField("DeserializerCollection path", deserializerCollectionPath);
            if (GUILayout.Button("Scan for ghosts"))
            {
                FindAllGhosts();
            }

            if (m_GhostList == null)
            {
                m_GhostList =
                    new UnityEditorInternal.ReorderableList(m_GhostTypes, typeof(GhostType), true, false, false, false);
                m_GhostList.drawElementCallback = (Rect rect, int index, bool isActive, bool isFocused) =>
                {
                    m_GhostTypes[index].generate = EditorGUI.Toggle(rect, m_GhostTypes[index].serializerType.Name,
                                                                    m_GhostTypes[index].generate);
                };
            }

            var listRect = new Rect(0, EditorGUIUtility.singleLineHeight * 6, position.width, EditorGUIUtility.singleLineHeight * (m_GhostTypes.Count + 1));

            m_GhostList.DoList(listRect);

            if (GUILayout.Button("Generate Collection"))
            {
                var serializerFile   = Path.Combine(Application.dataPath, serializerCollectionPath);
                var deserializerFile = Path.Combine(Application.dataPath, deserializerCollectionPath);

                string ghostSerializerInst        = "";
                string ghostDeserializerInst      = "";
                string ghostFind                  = "";
                string ghostBeginSerialize        = "";
                string ghostCalculateImportance   = "";
                string ghostWantsPredictionDelta  = "";
                string ghostSnapshotSize          = "";
                string ghostInvokeSerialize       = "";
                string ghostSerializerName        = "";
                string ghostInitializeDeserialize = "";
                string ghostBeginDeserialize      = "";
                string ghostInvokeDeserialize     = "";
                string ghostInvokeSpawn           = "";
                for (int i = 0; i < m_GhostTypes.Count; ++i)
                {
                    if (m_GhostTypes[i].generate)
                    {
                        ghostSerializerInst += GhostSerializerInstanceTemplate
                                               .Replace("/*$GHOST_SERIALIZER_TYPE*/", m_GhostTypes[i].serializerType.Name);
                        ghostDeserializerInst += GhostDeserializerInstanceTemplate
                                                 .Replace("/*$GHOST_SNAPSHOT_TYPE*/", m_GhostTypes[i].snapshotType.Name);
                        ghostFind += GhostFindTemplate
                                     .Replace("/*$GHOST_SERIALIZER_TYPE*/", m_GhostTypes[i].serializerType.Name)
                                     .Replace("/*$GHOST_SERIALIZER_INDEX*/", i.ToString());
                        ghostBeginSerialize += GhostBeginSerializeTemplate
                                               .Replace("/*$GHOST_SERIALIZER_TYPE*/", m_GhostTypes[i].serializerType.Name);
                        ghostCalculateImportance += GhostCalculateImportanceTemplate
                                                    .Replace("/*$GHOST_SERIALIZER_TYPE*/", m_GhostTypes[i].serializerType.Name)
                                                    .Replace("/*$GHOST_SERIALIZER_INDEX*/", i.ToString());
                        ghostWantsPredictionDelta += GhostWantsPredictionDeltaTemplate
                                                     .Replace("/*$GHOST_SERIALIZER_TYPE*/", m_GhostTypes[i].serializerType.Name)
                                                     .Replace("/*$GHOST_SERIALIZER_INDEX*/", i.ToString());
                        ghostSnapshotSize += GhostSnapshotSizeTemplate
                                             .Replace("/*$GHOST_SERIALIZER_TYPE*/", m_GhostTypes[i].serializerType.Name)
                                             .Replace("/*$GHOST_SERIALIZER_INDEX*/", i.ToString());
                        ghostInvokeSerialize += GhostInvokeSerializeTemplate
                                                .Replace("/*$GHOST_COLLECTION_PREFIX*/", "")
                                                .Replace("/*$GHOST_SNAPSHOT_TYPE*/", m_GhostTypes[i].snapshotType.Name)
                                                .Replace("/*$GHOST_SERIALIZER_TYPE*/", m_GhostTypes[i].serializerType.Name)
                                                .Replace("/*$GHOST_SERIALIZER_INDEX*/", i.ToString());
                        ghostSerializerName += GhostSerializerNameTemplate
                                               .Replace("/*$GHOST_SERIALIZER_TYPE*/", m_GhostTypes[i].serializerType.Name);
                        ghostInitializeDeserialize += GhostInitializeDeserializeTemplate
                                                      .Replace("/*$GHOST_SNAPSHOT_TYPE*/", m_GhostTypes[i].snapshotType.Name)
                                                      .Replace("/*$GHOST_SERIALIZER_INDEX*/", i.ToString())
                                                      .Replace("/*$GHOST_SPAWNER_TYPE*/", m_GhostTypes[i].spawnerType.Name);
                        ghostBeginDeserialize += GhostBeginDeserializeTemplate
                                                 .Replace("/*$GHOST_SNAPSHOT_TYPE*/", m_GhostTypes[i].snapshotType.Name);
                        ghostInvokeDeserialize += GhostInvokeDeserializeTemplate
                                                  .Replace("/*$GHOST_COLLECTION_PREFIX*/", "")
                                                  .Replace("/*$GHOST_SNAPSHOT_TYPE*/", m_GhostTypes[i].snapshotType.Name)
                                                  .Replace("/*$GHOST_SERIALIZER_INDEX*/", i.ToString());
                        ghostInvokeSpawn += GhostInvokeSpawnTemplate
                                            .Replace("/*$GHOST_COLLECTION_PREFIX*/", "")
                                            .Replace("/*$GHOST_SNAPSHOT_TYPE*/", m_GhostTypes[i].snapshotType.Name)
                                            .Replace("/*$GHOST_SERIALIZER_INDEX*/", i.ToString());
                    }
                }
                string serializerContent = GhostSerializerCollectionTemplate
                                           .Replace("/*$GHOST_SERIALIZER_INSTANCES*/", ghostSerializerInst)
                                           .Replace("/*$GHOST_DESERIALIZER_INSTANCES*/", ghostDeserializerInst)
                                           .Replace("/*$GHOST_FIND_CHECKS*/", ghostFind)
                                           .Replace("/*$GHOST_BEGIN_SERIALIZE*/", ghostBeginSerialize)
                                           .Replace("/*$GHOST_CALCULATE_IMPORTANCE*/", ghostCalculateImportance)
                                           .Replace("/*$GHOST_WANTS_PREDICTION_DELTA*/", ghostWantsPredictionDelta)
                                           .Replace("/*$GHOST_SNAPSHOT_SIZE*/", ghostSnapshotSize)
                                           .Replace("/*$GHOST_INVOKE_SERIALIZE*/", ghostInvokeSerialize)
                                           .Replace("/*$GHOST_SERIALIZER_NAMES*/", ghostSerializerName)
                                           .Replace("/*$GHOST_INITIALIZE_DESERIALIZE*/", ghostInitializeDeserialize)
                                           .Replace("/*$GHOST_BEGIN_DESERIALIZE*/", ghostBeginDeserialize)
                                           .Replace("/*$GHOST_INVOKE_DESERIALIZE*/", ghostInvokeDeserialize)
                                           .Replace("/*$GHOST_INVOKE_SPAWN*/", ghostInvokeSpawn)
                                           .Replace("/*$GHOST_SERIALIZER_COUNT*/", m_GhostTypes.Count.ToString())
                                           .Replace("/*$GHOST_COLLECTION_PREFIX*/", "")
                                           .Replace("/*$GHOST_SYSTEM_PREFIX*/", Application.productName);
                string deserializerContent = GhostDeserializerCollectionTemplate
                                             .Replace("/*$GHOST_SERIALIZER_INSTANCES*/", ghostSerializerInst)
                                             .Replace("/*$GHOST_DESERIALIZER_INSTANCES*/", ghostDeserializerInst)
                                             .Replace("/*$GHOST_FIND_CHECKS*/", ghostFind)
                                             .Replace("/*$GHOST_BEGIN_SERIALIZE*/", ghostBeginSerialize)
                                             .Replace("/*$GHOST_CALCULATE_IMPORTANCE*/", ghostCalculateImportance)
                                             .Replace("/*$GHOST_WANTS_PREDICTION_DELTA*/", ghostWantsPredictionDelta)
                                             .Replace("/*$GHOST_SNAPSHOT_SIZE*/", ghostSnapshotSize)
                                             .Replace("/*$GHOST_INVOKE_SERIALIZE*/", ghostInvokeSerialize)
                                             .Replace("/*$GHOST_SERIALIZER_NAMES*/", ghostSerializerName)
                                             .Replace("/*$GHOST_INITIALIZE_DESERIALIZE*/", ghostInitializeDeserialize)
                                             .Replace("/*$GHOST_BEGIN_DESERIALIZE*/", ghostBeginDeserialize)
                                             .Replace("/*$GHOST_INVOKE_DESERIALIZE*/", ghostInvokeDeserialize)
                                             .Replace("/*$GHOST_INVOKE_SPAWN*/", ghostInvokeSpawn)
                                             .Replace("/*$GHOST_SERIALIZER_COUNT*/", m_GhostTypes.Count.ToString())
                                             .Replace("/*$GHOST_COLLECTION_PREFIX*/", "")
                                             .Replace("/*$GHOST_SYSTEM_PREFIX*/", Application.productName);
                File.WriteAllText(serializerFile, serializerContent);
                File.WriteAllText(deserializerFile, deserializerContent);
            }
        }
 protected override void DrawCustomValue(ref Rect position, SerializedProperty property, GUIContent label)
 {
     CreateList(property);
     Indent(ref position);
     list.DoList(position);
 }
예제 #10
0
 public void Draw(Rect position, bool addRemove = true)
 {
     reorderableList.displayAdd    = addRemove;
     reorderableList.displayRemove = addRemove;
     reorderableList.DoList(position);
 }