Example #1
0
    protected override void Edit(bool array)
    {
        DEditorGUI.WithLabel("Compression", () =>
        {
            PropertyType.CompressionEnabled = DEditorGUI.Toggle(PropertyType.CompressionEnabled);


            EditorGUI.BeginDisabledGroup(PropertyType.CompressionEnabled == false);

            PropertyType.MinValue = Mathf.Min(DEditorGUI.IntFieldOverlay(PropertyType.MinValue, "Min"),
                                              PropertyType.MaxValue - 1);
            PropertyType.MaxValue = Mathf.Max(DEditorGUI.IntFieldOverlay(PropertyType.MaxValue, "Max"),
                                              PropertyType.MinValue + 1);

            GUILayout.Label("Bits: " + PropertyType.BitsRequired, EditorStyles.miniLabel, GUILayout.ExpandWidth(false));

            EditorGUI.EndDisabledGroup();
        });

        //DEditorGUI.WithLabel("Min Value", () => { PropertyType.MinValue = EditorGUILayout.IntField(PropertyType.MinValue); });
        //DEditorGUI.WithLabel("Max Value", () => { PropertyType.MaxValue = EditorGUILayout.IntField(PropertyType.MaxValue); });

        //DEditorGUI.WithLabel("Info", () => {
        //  EditorGUILayout.LabelField("Bits: " + BoltMath.BitsRequired(PropertyType.MaxValue - PropertyType.MinValue));
        //});

        //PropertyType.MinValue = Mathf.Min(PropertyType.MinValue, PropertyType.MaxValue - 1);
        //PropertyType.MaxValue = Mathf.Max(PropertyType.MaxValue, PropertyType.MinValue + 1);
    }
Example #2
0
 protected override void Edit(bool array)
 {
     DEditorGUI.WithLabel("Encoding & Length", () =>
     {
         PropertyType.Encoding  = (StringEncodings)EditorGUILayout.EnumPopup(PropertyType.Encoding);
         PropertyType.MaxLength =
             Mathf.Clamp(DEditorGUI.IntFieldOverlay(PropertyType.MaxLength, "Max Length (1 - 140)"), 1, 140);
     });
 }
    void EditCommand(CommandDefinition def)
    {
        DEditorGUI.WithLabel("Correction Interpolation", () =>
        {
            def.SmoothFrames = DEditorGUI.IntFieldOverlay(def.SmoothFrames, "Frames");
        });

        //DEditorGUI.WithLabel("Compress Zero Values", () => {
        //  def.CompressZeroValues = EditorGUILayout.Toggle(def.CompressZeroValues);
        //});

        // add button
        DEditorGUI.Header("Input", "commands");
        GUILayout.Space(2);
        EditPropertyList(def, def.Input);

        // add button
        DEditorGUI.Header("Result", "position");
        GUILayout.Space(2);
        EditPropertyList(def, def.Result);
    }
    void EditProperty(AssetDefinition def, PropertyDefinition p, bool first, bool last)
    {
        BeginBackground();

        GUILayout.BeginHorizontal(DEditorGUI.HeaderBackground, GUILayout.Height(DEditorGUI.HEADER_HEIGHT));

        if ((Event.current.modifiers & EventModifiers.Control) == EventModifiers.Control)
        {
            if (DEditorGUI.IconButton("minus-editor"))
            {
                if (EditorUtility.DisplayDialog("Delete Property", string.Format("Do you want to delete '{0}' (Property)?", p.Name), "Yes", "No"))
                {
                    p.Deleted = true;
                }
            }
        }
        else
        {
            if (DEditorGUI.Toggle("arrow-down", "arrow-right", p.Expanded && (p.PropertyType.HasSettings || p.PropertyType.MecanimApplicable)))
            {
                p.Expanded = !p.Expanded;
            }
        }

        if (def is StateDefinition || def is ObjectDefinition)
        {
            p.Name = DEditorGUI.TextFieldOverlay(p.Name, p.Priority.ToString(), GUILayout.Width(181));

            switch (p.ReplicationMode)
            {
            case ReplicationMode.Everyone:
                DEditorGUI.Toggle("controller-plus", true);
                break;

            case ReplicationMode.EveryoneExceptController:
                DEditorGUI.Toggle("controller", false);
                break;

            case ReplicationMode.OnlyOwnerAndController:
                DEditorGUI.Toggle("controller-only", true);
                break;

            case ReplicationMode.LocalForEachPlayer:
                DEditorGUI.Toggle("owner-only", true);
                break;
            }
        }
        else
        {
            p.Name = EditorGUILayout.TextField(p.Name, GUILayout.Width(200));
        }

        DEditorGUI.SetTooltip("Name. The name of this property, has to be a valid C# property name.");

        // edit property type
        DEditorGUI.PropertyTypePopup(def, p);
        DEditorGUI.SetTooltip("Type. The type of this property.");

        EditorGUI.BeginDisabledGroup(def.SortOrder != SortOrder.Manual);

        if (DEditorGUI.IconButton("arrow-down", !last))
        {
            p.Adjust += 1;
        }

        if (DEditorGUI.IconButton("arrow-up", !first))
        {
            p.Adjust -= 1;
        }

        EditorGUI.EndDisabledGroup();
        EditorGUILayout.EndHorizontal();

        if (p.Controller)
        {
            p.ReplicationMode = ReplicationMode.Everyone;
            p.Controller      = false;
            Save();
        }

        if (p.Expanded)
        {
            GUILayout.Space(2);

            //DEditorGUI.WithLabel("Comment", () => {
            //  p.Comment = EditorGUILayout.TextField(p.Comment);
            //});

            if (def is StateDefinition || def is ObjectDefinition)
            {
                DEditorGUI.WithLabel("Replication", () =>
                {
                    p.Priority        = DEditorGUI.EditPriority(p.Priority, p.PropertyType.HasPriority);
                    p.ReplicationMode = (ReplicationMode)EditorGUILayout.EnumPopup(p.ReplicationMode);
                });
            }

            if (def is CommandDefinition)
            {
                if (p.PropertyType.CanSmoothCorrections && ((CommandDefinition)def).Result.Contains(p))
                {
                    DEditorGUI.WithLabel("Smooth Corrections", () =>
                    {
                        p.CommandAssetSettings.SmoothCorrection = EditorGUILayout.Toggle(p.CommandAssetSettings.SmoothCorrection);
                    });
                }
            }

            if (p.PropertyType.MecanimApplicable && (def is StateDefinition))
            {
                DEditorGUI.WithLabel("Mecanim", () =>
                {
                    EditorGUILayout.BeginHorizontal();

                    if (p.PropertyType is PropertyTypeFloat)
                    {
                        p.StateAssetSettings.MecanimMode = (MecanimMode)EditorGUILayout.EnumPopup(p.StateAssetSettings.MecanimMode);
                        EditorGUI.BeginDisabledGroup(p.StateAssetSettings.MecanimMode == MecanimMode.Disabled);

                        p.StateAssetSettings.MecanimDirection = (MecanimDirection)EditorGUILayout.EnumPopup(p.StateAssetSettings.MecanimDirection);

                        switch (p.StateAssetSettings.MecanimMode)
                        {
                        case MecanimMode.Parameter:
                            if (p.StateAssetSettings.MecanimDirection == MecanimDirection.UsingAscensionProperties)
                            {
                                p.StateAssetSettings.MecanimDamping = DEditorGUI.FloatFieldOverlay(p.StateAssetSettings.MecanimDamping, "Damping Time");
                            }

                            break;

                        case MecanimMode.LayerWeight:
                            p.StateAssetSettings.MecanimLayer = DEditorGUI.IntFieldOverlay(p.StateAssetSettings.MecanimLayer, "Layer Index");
                            break;
                        }

                        EditorGUI.EndDisabledGroup();
                    }
                    else
                    {
                        p.StateAssetSettings.MecanimMode = (MecanimMode)(int)EditorGUILayout.Popup((int)p.StateAssetSettings.MecanimMode, new string[] { "Disabled", "Parameter" });

                        EditorGUI.BeginDisabledGroup(p.StateAssetSettings.MecanimMode == MecanimMode.Disabled);
                        p.StateAssetSettings.MecanimDirection = (MecanimDirection)EditorGUILayout.EnumPopup(p.StateAssetSettings.MecanimDirection);

                        if (p.PropertyType is PropertyTypeTrigger)
                        {
                            p.StateAssetSettings.MecanimLayer = DEditorGUI.IntFieldOverlay(p.StateAssetSettings.MecanimLayer, "Layer Index");
                        }
                        EditorGUI.EndDisabledGroup();
                    }

                    EditorGUILayout.EndHorizontal();
                });
            }

            if (p.PropertyType.HasSettings)
            {
                PropertyEditorRegistry.GetEditor(p.PropertyType.GetType()).Edit(def, p);
            }
        }
        else
        {
            GUILayout.Space(2);
        }

        EditorGUILayout.EndVertical();
    }
    void EditState(StateDefinition def)
    {
        DEditorGUI.WithLabel("Inheritance", () =>
        {
            def.IsAbstract = DEditorGUI.ToggleDropdown("Is Abstract", "Is Concrete", def.IsAbstract);
            def.ParentGuid = DEditorGUI.AssetPopup("Parent: ", Project.States.Cast <AssetDefinition>(), def.ParentGuid, Project.GetInheritanceTree(def));
        });

        EditorGUI.BeginDisabledGroup(def.IsAbstract);

        DEditorGUI.WithLabel("Bandwidth", () =>
        {
            GUILayout.BeginHorizontal();
            def.PacketMaxBits       = Mathf.Clamp(DEditorGUI.IntFieldOverlay(def.PacketMaxBits, "Bits/Packet"), 128, 4096);
            def.PacketMaxProperties = Mathf.Clamp(DEditorGUI.IntFieldOverlay(def.PacketMaxProperties, "Properties/Packet"), 1, 255);
            GUILayout.EndHorizontal();
        });

        EditorGUI.EndDisabledGroup();

        DEditorGUI.WithLabel("Import Mecanim Modes", () => {
            replicationMode  = (ReplicationMode)EditorGUILayout.EnumPopup("Replication Mode", replicationMode);
            mecanimDirection = (MecanimDirection)EditorGUILayout.EnumPopup("Mecanim Mode", mecanimDirection);
        });

        DEditorGUI.WithLabel("Import Mecanim Parameters", () =>
        {
            mecanimController = EditorGUILayout.ObjectField(mecanimController, typeof(RuntimeAnimatorController), true) as RuntimeAnimatorController;

            if (mecanimController)
            {
                if (GUILayout.Button("Import", EditorStyles.miniButton))
                {
                    try
                    {
                        AC ac = (AC)mecanimController;

#if UNITY_5
                        for (int i = 0; i < ac.parameters.Length; ++i)
                        {
                            ImportMecanimParameter(def, ac.parameters[i]);
                        }
#else
                        for (int i = 0; i < ac.parameterCount; ++i)
                        {
                            ImportMecanimParameter(def, ac.GetParameter(i));
                        }

                        for (int i = 0; i < ac.layerCount; ++i)
                        {
                            ImportMecanimLayer(def, ac, i);
                        }
#endif

                        Save();
                    }
                    finally
                    {
                        mecanimController = null;
                    }
                }
            }
        });

        var groups =
            def.Properties
            .Where(x => x.PropertyType.MecanimApplicable)
            .Where(x => x.StateAssetSettings.MecanimMode != MecanimMode.Disabled)
            .GroupBy(x => x.StateAssetSettings.MecanimDirection);

        if (groups.Count() == 1)
        {
            var currentDirection = groups.First().Key;

            DEditorGUI.WithLabel("Mecanim (State Wide)", () =>
            {
                var selectedDirection = (MecanimDirection)EditorGUILayout.EnumPopup(currentDirection);

                if (currentDirection != selectedDirection)
                {
                    foreach (var property in def.Properties.Where(x => x.PropertyType.MecanimApplicable))
                    {
                        property.StateAssetSettings.MecanimDirection = selectedDirection;
                    }

                    Save();
                }
            });
        }
        else if (groups.Count() > 1)
        {
            DEditorGUI.WithLabel("Mecanim (State Wide)", () =>
            {
                string[] options = new string[] { "Using Animator Methods", "Using Bolt Properties", "Mixed (WARNING)" };

                int index = EditorGUILayout.Popup(2, options);

                if (index != 2)
                {
                    foreach (var property in def.Properties.Where(x => x.PropertyType.MecanimApplicable))
                    {
                        property.StateAssetSettings.MecanimDirection = (MecanimDirection)index;
                    }

                    Save();
                }
            });
        }

        EditPropertyList(def, def.Properties);

        Guid guid = def.ParentGuid;

        while (guid != Guid.Empty)
        {
            var parent = Project.FindState(guid);
            GUILayout.Label(string.Format("Inherited from {0}", parent.Name), DEditorGUI.MiniLabelButtonStyle);

            EditorGUI.BeginDisabledGroup(true);
            EditPropertyList(parent, parent.Properties);
            EditorGUI.EndDisabledGroup();

            guid = parent.ParentGuid;
        }
    }