Exemple #1
0
        /// <summary>
        /// Get the hero object template you want to work with.
        /// </summary>
        /// <typeparam name="T">The type of data for the action field.</typeparam>
        /// <param name="data">The data for the action field.</param>
        /// <returns>The data for the action field.</returns>
        public static T GetTargetHeroTemplate <T>(T data) where T : ITargetHeroObject
        {
            data.objectType = new HeroField.HeroObjectTypeFieldB().SetValues(data.objectType, -5);
            switch (data.objectType)
            {
            case 1:
                data.targetHeroObject = SimpleLayout.ObjectField(data.targetHeroObject, HeroKitCommon.GetWidthForField(213));
                break;

            case 2:
                data = GetThisHeroObject(data);
                break;

            case 3:
                data = GetHeroObjectInVariables(data);
                break;

            case 4:
                data = GetHeroObjectInScene(data);
                break;

            case 5:
                data = GetHeroObjectInProperties(data);
                break;

            case 6:
                data = GetHeroObjectInGlobals(data);
                break;
            }

            return(data);
        }
        /// <summary>
        /// Choose the rigidbody for object in this state.
        /// </summary>
        private static Rigidbody GetRigidbody(int rigidbodyType)
        {
            Rigidbody rigidbody = null;

            switch (rigidbodyType)
            {
            case 0:     // not set
                break;

            case 1:     // use default rigidbody
                GameObject template = Resources.Load <GameObject>("Hero Templates/Components/" + "HeroKit 3D Rigidbody");
                rigidbody = (template != null) ? template.GetComponent <Rigidbody>() : null;
                break;

            case 2:     // use custom rigidbody
                rigidbody = SimpleLayout.ObjectField(rigidbody);
                break;

            case 3:     // no rigidbody
                rigidbody = null;
                break;

            case 4:     // heavy rigidbody
                GameObject templateHeavy = Resources.Load <GameObject>("Hero Templates/Components/" + "HeroKit 3D Heavy Rigidbody");
                rigidbody = (templateHeavy != null) ? templateHeavy.GetComponent <Rigidbody>() : null;
                break;
            }

            return(rigidbody);
        }
Exemple #3
0
        // --------------------------------------------------------------
        // Action Fields
        // --------------------------------------------------------------

        /// <summary>
        /// Get a hero property.
        /// </summary>
        /// <param name="title">Title for action field.</param>
        /// <param name="actionParams">Action field parameters.</param>
        /// <param name="actionField">Action field.</param>
        public static void BuildField(string title, HeroActionParams actionParams, HeroActionField actionField)
        {
            // create the fields
            HeroPropertyFieldData data = CreateFieldData(title, actionField, actionParams.heroObject);

            //-----------------------------------------
            // Display this title above the field
            //-----------------------------------------
            if (data.title != "")
            {
                SimpleLayout.Label(data.title);
            }
            SimpleLayout.BeginHorizontal();

            //-----------------------------------------
            // Get the integer list you want to work with.
            // The integer list is in hero object editor > Variables
            //-----------------------------------------
            data.fieldValue = SimpleLayout.ObjectField(data.fieldValue, 200);

            //-----------------------------------------
            // assign values back to hero object fields
            //-----------------------------------------
            actionField.heroProperties[0] = data.fieldValue;

            //-----------------------------------------
            // Visual stuff
            //-----------------------------------------
            SimpleLayout.Space();
            SimpleLayout.EndHorizontal();
        }
Exemple #4
0
        /// <summary>
        /// Draw item type
        /// </summary>
        private static void DrawRange()
        {
            // item type field
            string[]       items    = { "Projectile launched at target", "Everything within radius around Caster", "Directly on Target" };
            DropDownValues itemList = new DropDownValues();

            itemList.setValues("", items);

            SimpleLayout.BeginVertical(SimpleGUI.Fields.Box.StyleB);
            SimpleLayout.BeginHorizontal();
            intFields[2].value = SimpleLayout.DropDownList(intFields[2].value, itemList, 0, HeroKit.Editor.HeroKitCommon.GetWidthForField(60, 200));
            SimpleLayout.Label("How ability is used");
            SimpleLayout.Space();
            SimpleLayout.EndHorizontal();

            // projectile or radius
            if (intFields[2].value == 1 || intFields[2].value == 2)
            {
                SimpleLayout.BeginHorizontal();
                intFields[3].value = SimpleLayout.IntField(intFields[3].value);
                SimpleLayout.Label("Range (in meters)");
                SimpleLayout.Space();
                SimpleLayout.EndHorizontal();
            }

            // projectile
            if (intFields[2].value == 1)
            {
                SimpleLayout.BeginHorizontal();
                intFields[4].value = SimpleLayout.IntField(intFields[4].value);
                SimpleLayout.Label("Speed of projectile");
                SimpleLayout.Space();
                SimpleLayout.EndHorizontal();

                // particle effect on target
                SimpleLayout.BeginHorizontal();
                uoFields[3].value = SimpleLayout.ObjectField(uoFields[3].value as ParticleSystem, HeroKit.Editor.HeroKitCommon.GetWidthForField(60, 200));
                SimpleLayout.Label("Particle effect for projectile");
                SimpleLayout.Space();
                SimpleLayout.EndHorizontal();
            }

            // particle effect on target
            SimpleLayout.BeginHorizontal();
            uoFields[2].value = SimpleLayout.ObjectField(uoFields[2].value as ParticleSystem, HeroKit.Editor.HeroKitCommon.GetWidthForField(60, 200));
            SimpleLayout.Label("Particle effect on target");
            SimpleLayout.Space();
            SimpleLayout.EndHorizontal();

            // particle effect on caster
            SimpleLayout.BeginHorizontal();
            uoFields[1].value = SimpleLayout.ObjectField(uoFields[1].value as ParticleSystem, HeroKit.Editor.HeroKitCommon.GetWidthForField(60, 200));
            SimpleLayout.Label("Particle effect on caster");
            SimpleLayout.Space();
            SimpleLayout.EndHorizontal();


            SimpleLayout.EndVertical();
        }
Exemple #5
0
        /// <summary>
        /// Draw the body of the block.
        /// </summary>
        private static void DrawBody()
        {
            SimpleLayout.BeginVertical(Box.StyleCanvasBox);

            SimpleLayout.BeginVertical(Box.StyleB);

            SimpleLayout.Label("Action (this is used during gameplay):");
            heroAction.action = SimpleLayout.ObjectField(heroAction.action, 400);

            SimpleLayout.Label("Action (this is used to create editor fields for action):");
            heroAction.actionFields = SimpleLayout.ObjectField(heroAction.actionFields, 400);

            SimpleLayout.EndVertical();

            // -------------

            SimpleLayout.BeginVertical(Box.StyleB);

            SimpleLayout.Label("Prefix (adds text in front of the action in the menu):");
            heroAction.title = SimpleLayout.TextField(heroAction.title);

            SimpleLayout.Label("Description (this appears below editor fields for action):");
            heroAction.description = SimpleLayout.TextArea(heroAction.description);

            SimpleLayout.EndVertical();

            // --------------

            SimpleLayout.BeginVertical(Box.StyleB);

            SimpleLayout.Label("Indent This Action (indents this action in menu. 0=no indent):");
            heroAction.indentThis = SimpleLayout.IntField(heroAction.indentThis);

            SimpleLayout.Label("Indent Next Action (indents the next action in menu. 0=no indent):");
            heroAction.indentNext = SimpleLayout.IntField(heroAction.indentNext);

            SimpleLayout.Label("Color (The color of this action in the menu):");
            heroAction.titleColor = SimpleLayout.ColorField(heroAction.titleColor, 400);

            SimpleLayout.EndVertical();

            // --------------

            SimpleLayout.Label("Version (version of this action + developer notes):");
            heroAction.version = SimpleLayout.TextArea(heroAction.version);

            SimpleLayout.EndVertical();
        }
Exemple #6
0
        /// <summary>
        /// If visuals type was prefab, draw the prefab preview.
        /// </summary>
        /// <param name="is2D">If we are working with 2D visuals, set this to true.</param>
        private static void DrawPrefabForState(bool is2D = false)
        {
            SimpleLayout.BeginVertical(Box.StyleB);

            stateBlock.heroVisuals.hasMesh            = false;
            stateBlock.heroVisuals.imageMesh          = null;
            stateBlock.heroVisuals.hasAnimator        = false;
            stateBlock.heroVisuals.animator           = null;
            stateBlock.heroVisuals.animatorController = null;
            stateBlock.heroVisuals.avatar             = null;

            // display the prefab
            SimpleLayout.Label("Prefab:");
            stateBlock.heroVisuals.prefab = SimpleLayout.ObjectField(stateBlock.heroVisuals.prefab);
            if (stateBlock.heroVisuals.prefab != null && PrefabUtility.GetPrefabType(stateBlock.heroVisuals.prefab) != PrefabType.Prefab)
            {
                stateBlock.heroVisuals.prefab = null;
            }
            if (stateBlock.heroVisuals.prefab != null)
            {
                // attach mesh to hero kit object if it exists
                MeshFilter meshFilter = stateBlock.heroVisuals.prefab.GetComponent <MeshFilter>();
                if (meshFilter != null)
                {
                    stateBlock.heroVisuals.hasMesh   = true;
                    stateBlock.heroVisuals.imageMesh = meshFilter.sharedMesh;
                }

                // attach animator to hero kit object if it exists
                Animator animator = stateBlock.heroVisuals.prefab.GetComponent <Animator>();
                if (animator != null)
                {
                    stateBlock.heroVisuals.hasAnimator        = true;
                    stateBlock.heroVisuals.animator           = animator;
                    stateBlock.heroVisuals.animatorController = animator.runtimeAnimatorController;
                    stateBlock.heroVisuals.avatar             = animator.avatar;
                }
            }
            SimpleLayout.EndVertical();

            // attach rigidbody
            DrawRigidbodyForState(is2D);

            // display preview
            DrawVisualPreview(stateBlock.heroVisuals.prefab);
        }
Exemple #7
0
        /// <summary>
        /// Fields for the hero property (unity objects).
        /// </summary>
        private static void DrawUnityObjects()
        {
            List <UnityObjectField> items = propertyBlock.itemProperties.unityObjects.items;

            // exit early if there are no values
            if (items == null || items.Count == 0)
            {
                return;
            }

            SimpleLayout.BeginVertical(SimpleGUI.Fields.Box.StyleB);
            for (int i = 0; i < items.Count; i++)
            {
                SimpleLayout.Label(items[i].name + ":");

                switch (items[i].objectType)
                {
                case 1:     // audio
                    items[i].value = SimpleLayout.ObjectField(items[i].value as AudioClip, HeroKitCommon.GetWidthForField(60, 150));
                    break;

                case 2:     // sprite
                    items[i].value = SimpleLayout.ObjectField(items[i].value as Sprite, HeroKitCommon.GetWidthForField(60, 150));
                    break;

                case 3:     // scene
                    items[i].value = SimpleLayout.ObjectField(items[i].value as SceneAsset, HeroKitCommon.GetWidthForField(60, 150));
                    if (items[i].value != null)
                    {
                        // add the scene to the editor build settings if it doesn't already exist there.
                        HeroKitCommon.AddSceneToBuildSettings(items[i].value as SceneAsset);
                    }
                    break;

                case 4:     // particle system
                    items[i].value = SimpleLayout.ObjectField(items[i].value as ParticleSystem, HeroKitCommon.GetWidthForField(60, 150));
                    break;

                case 5:     // script
                    items[i].value = SimpleLayout.ObjectField(items[i].value as MonoScript, HeroKitCommon.GetWidthForField(60, 150));
                    break;
                }
            }
            SimpleLayout.EndVertical();
        }
Exemple #8
0
        /// <summary>
        /// Fields for the hero property (hero objects).
        /// </summary>
        private static void DrawHeroObjects()
        {
            List <HeroObjectField> items = propertyBlock.itemProperties.heroObjects.items;

            // exit early if there are no values
            if (items == null || items.Count == 0)
            {
                return;
            }

            SimpleLayout.BeginVertical(SimpleGUI.Fields.Box.StyleB);
            for (int i = 0; i < items.Count; i++)
            {
                SimpleLayout.Label(items[i].name + ":");
                items[i].value = SimpleLayout.ObjectField(items[i].value, HeroKitCommon.GetWidthForField(60, 150));
            }
            SimpleLayout.EndVertical();
        }
Exemple #9
0
    /// <summary>
    /// Display a custom inspector for the hero kit object.
    /// </summary>
    public override void OnInspectorGUI()
    {
        HeroObject oldHeroObject = heroKitObject.heroObject;

        heroKitObject.heroObject = SimpleLayout.ObjectField("Hero Object", 100, heroKitObject.heroObject, 200, false);
        HeroObject newHeroObject = heroKitObject.heroObject;

        // has hero object changed? if yes, refresh graphics
        if (newHeroObject != oldHeroObject)
        {
            HeroKit.Scene.HeroKitCommonRuntime.RefreshVisuals(heroKitObject);
        }

        if (heroKitObject.heroObject == null)
        {
            SimpleLayout.BeginVertical(EditorStyles.helpBox);
            SimpleLayout.Label("Drag the hero object you want to use from the Project Tab into the field above. Or you can choose an existing hero object by selecting the icon to the right of the field above.\n\nIf you want to create a new hero object and assign it to this field, click the button below.", true);
            SimpleLayout.EndVertical();
            if (GUILayout.Button("Create & Assign Hero Object"))
            {
                heroKitObject.heroObject = HeroKitCommon.AddHeroObjectToFolder(false);
                Selection.activeObject   = heroKitObject.transform;
            }
        }

        else if (heroKitObject.heroObject != null)
        {
            if (GUILayout.Button("Edit Hero Object"))
            {
                HeroKitEditor.ButtonClickHeroObjectAsset(heroKitObject.heroObject);
            }

            if (GUILayout.Button("Show Details"))
            {
                ToggleDetails();
            }

            // show existing inspector
            if (showDetails)
            {
                base.OnInspectorGUI();
            }
        }
    }
Exemple #10
0
        /// <summary>
        /// Draw the body of the block.
        /// </summary>
        private static void DrawBody()
        {
            SimpleLayout.BeginVertical(Box.StyleCanvasBox);

            // draw name of the block
            action.name = HeroKitCommon.DrawBlockName(action.name);

            SimpleLayout.Line();

            // get current action template on hero object
            HeroKitAction oldTemplate = action.actionTemplate;

            // draw action field for block
            SimpleLayout.Space(5);
            SimpleLayout.BeginHorizontal();
            SimpleLayout.Label("Action:");
            action.actionTemplate = SimpleLayout.ObjectField(action.actionTemplate, HeroKitCommon.GetWidthForField(85));

            SimpleLayout.Space();
            SimpleLayout.EndHorizontal();

            // SHOW FIELDS FOR SPECIFIC ACTION
            if (action.actionTemplate != null)
            {
                SimpleLayout.Space(5);
                SimpleLayout.Line();
                SimpleLayout.Space(5);

                // build fields
                ActionBlockBuilder.BuildFields(heroObject, action, action.actionTemplate, oldTemplate);

                // build description for action
                SimpleLayout.Space(5);
                SimpleLayout.Line();
                SimpleLayout.Label("Description:");
                SimpleLayout.Label(action.actionTemplate.description, true);
            }


            SimpleLayout.EndVertical();
        }
Exemple #11
0
        // --------------------------------------------------------------
        // Methods (Fields)
        // --------------------------------------------------------------

        /// <summary>
        /// A field for a hero property file.
        /// </summary>
        private static void DrawItemType()
        {
            SimpleLayout.BeginHorizontal();
            SimpleLayout.Label("Item Type:");
            SimpleLayout.Space(13);
            propertyBlock.propertyTemplate = SimpleLayout.ObjectField(propertyBlock.propertyTemplate, HeroKitCommon.GetWidthForField(120));
            SimpleLayout.Space();
            SimpleLayout.EndHorizontal();

            // SHOW FIELDS FOR SPECIFIC HERO PROPERTY
            // if hero property has been removed, sanitize properties list
            if (propertyBlock.propertyTemplate != null)
            {
                SimpleLayout.Space(5);
                SimpleLayout.Line();
            }
            else
            {
                propertyBlock.itemProperties = new HeroList();
            }
        }
Exemple #12
0
        // --------------------------------------------------------------
        // Action Fields
        // --------------------------------------------------------------

        /// <summary>
        /// Get a prefab.
        /// </summary>
        /// <param name="title">Title for action field.</param>
        /// <param name="actionParams">Action field parameters.</param>
        /// <param name="actionField">Action field.</param>
        /// <param name="titleToLeft">Show the title on the left?</param>
        /// <returns>The prefab.</returns>
        public static GameObject BuildField(string title, HeroActionParams actionParams, HeroActionField actionField, bool titleToLeft = false)
        {
            // create the fields
            PrefabValueData data = CreateFieldData(title, actionField, actionParams.heroObject);

            //-----------------------------------------
            // Display this title above the field
            //-----------------------------------------
            if (data.title != "" && !titleToLeft)
            {
                SimpleLayout.Label(data.title);
            }
            SimpleLayout.BeginHorizontal();
            if (data.title != "" && titleToLeft)
            {
                SimpleLayout.Label(data.title);
            }

            //-----------------------------------------
            // Get the prefab you want to work with.
            //-----------------------------------------
            data.fieldValue = SimpleLayout.ObjectField(data.fieldValue, 300);

            //-----------------------------------------
            // assign values back to hero object fields
            //-----------------------------------------
            actionField.gameObjects[0] = data.fieldValue;

            //-----------------------------------------
            // Visual stuff
            //-----------------------------------------
            SimpleLayout.Space();
            SimpleLayout.EndHorizontal();

            // return result
            return(actionField.gameObjects[0]);
        }
Exemple #13
0
        // --------------------------------------------------------------
        // Action Fields
        // --------------------------------------------------------------

        /// <summary>
        /// Get an object.
        /// </summary>
        /// <typeparam name="T">The type of object.</typeparam>
        /// <param name="title">Title for action field.</param>
        /// <param name="actionParams">Action field parameters.</param>
        /// <param name="actionField">Action field.</param>
        /// <param name="titleToLeft">Show the title on the left?</param>
        /// <returns>The object.</returns>
        public static T BuildField <T>(string title, HeroActionParams actionParams, HeroActionField actionField, bool titleToLeft = false) where  T : Object
        {
            // create the fields
            GetObjectValueData data = CreateFieldData(title, actionField, actionParams.heroObject);

            //-----------------------------------------
            // Display this title above the field
            //-----------------------------------------
            if (data.title != "" && !titleToLeft)
            {
                SimpleLayout.Label(data.title);
            }
            SimpleLayout.BeginHorizontal();
            if (data.title != "" && titleToLeft)
            {
                SimpleLayout.Label(data.title);
            }

            //-----------------------------------------
            // Get the object you want to work with
            //-----------------------------------------
            data.fieldValue = SimpleLayout.ObjectField(data.fieldValue as T, HeroKitCommon.GetWidthForField(60));

            //-----------------------------------------
            // assign values back to hero object fields
            //-----------------------------------------
            actionField.component = data.fieldValue;

            //-----------------------------------------
            // Visual stuff
            //-----------------------------------------
            SimpleLayout.Space();
            SimpleLayout.EndHorizontal();

            return(actionField.component as T);
        }
Exemple #14
0
        /// <summary>
        /// Draw the body of the block.
        /// </summary>
        private static void DrawItems()
        {
            // exit early if there are no items
            if (items == null || items.Count == 0)
            {
                HeroKitCommon.DrawNoItemsInList(blockName);
                return;
            }

            SimpleLayout.BeginVertical(Box.StyleCanvasBox);

            // display items (move up, move down, int field,
            for (int i = 0; i < items.Count; i++)
            {
                SimpleLayout.BeginHorizontal();
                HeroKitCommon.DrawListArrows(moveItemUp, moveItemDown, i);

                SimpleLayout.BeginVertical();
                items[i].objectType = new UnityObjectTypeField().SetValues(items[i].objectType, HeroKitCommon.GetWidthForField(270, 150));
                switch (items[i].objectType)
                {
                case 1:     // audio
                    items[i].value = SimpleLayout.ObjectField(items[i].value as AudioClip, HeroKitCommon.GetWidthForField(270, 150));
                    break;

                case 2:     // sprite
                    items[i].value = SimpleLayout.ObjectField(items[i].value as Sprite, HeroKitCommon.GetWidthForField(270, 150));
                    break;

                case 3:     // scene
                    items[i].value = SimpleLayout.ObjectField(items[i].value as SceneAsset, HeroKitCommon.GetWidthForField(270, 150));
                    if (items[i].value != null)
                    {
                        // add the scene to the editor build settings if it doesn't already exist there.
                        HeroKitCommon.AddSceneToBuildSettings(items[i].value as SceneAsset);
                    }
                    break;

                case 4:     // particle system
                    items[i].value = SimpleLayout.ObjectField(items[i].value as ParticleSystem, HeroKitCommon.GetWidthForField(270, 150));
                    break;

                case 5:     // mono script
                    items[i].value = SimpleLayout.ObjectField(items[i].value as MonoScript, HeroKitCommon.GetWidthForField(270, 150));
                    break;
                }
                items[i].name = SimpleLayout.StringListField(items[i].name, HeroKitCommon.GetWidthForField(270, 150));
                SimpleLayout.EndVertical();

                HeroKitCommon.DrawListButtons(addItem, copyItem, pasteItem, deleteItem, i);
                SimpleLayout.EndHorizontal();

                if (i != items.Count - 1)
                {
                    SimpleLayout.Line();
                }
            }

            SimpleLayout.EndVertical();

            SimpleLayout.Space(20);
        }
Exemple #15
0
        public static void MenuSkins()
        {
            // exit early if we don't want to show the menu skins.
            if (!toggleMenuSkins)
            {
                return;
            }

            HeroKitSettings settings = HeroKitCommon.LoadHeroSettings();
            int             distance = 10;

            SimpleLayout.BeginVertical(Box.StyleB);
            SimpleLayout.Label("Dialog Box");
            settings.dialogBox = SimpleLayout.ObjectField(settings.dialogBox, HeroKitCommon.GetWidthForField(65));
            if (settings.dialogBox == null)
            {
                HeroKitCommon.RefreshHeroSettings();
            }
            SimpleLayout.EndVertical();
            SimpleLayout.Space(distance);

            SimpleLayout.BeginVertical(Box.StyleB);
            SimpleLayout.Label("Fade Screen In and Out Window");
            settings.fadeInOutScreen = SimpleLayout.ObjectField(settings.fadeInOutScreen, HeroKitCommon.GetWidthForField(65));
            if (settings.fadeInOutScreen == null)
            {
                HeroKitCommon.RefreshHeroSettings();
            }
            SimpleLayout.EndVertical();
            SimpleLayout.Space(distance);

            SimpleLayout.BeginVertical(Box.StyleB);
            SimpleLayout.Label("Game Over Menu");
            settings.gameoverMenu = SimpleLayout.ObjectField(settings.gameoverMenu, HeroKitCommon.GetWidthForField(65));
            if (settings.gameoverMenu == null)
            {
                HeroKitCommon.RefreshHeroSettings();
            }
            SimpleLayout.EndVertical();
            SimpleLayout.Space(distance);

            SimpleLayout.BeginVertical(Box.StyleB);
            SimpleLayout.Label("Inventory Menu");
            settings.inventoryMenu = SimpleLayout.ObjectField(settings.inventoryMenu, HeroKitCommon.GetWidthForField(65));
            if (settings.inventoryMenu == null)
            {
                HeroKitCommon.RefreshHeroSettings();
            }
            SimpleLayout.Label("Inventory Item");
            settings.inventoryItem = SimpleLayout.ObjectField(settings.inventoryItem, HeroKitCommon.GetWidthForField(65));
            if (settings.inventoryItem == null)
            {
                HeroKitCommon.RefreshHeroSettings();
            }
            SimpleLayout.Label("Inventory Slot");
            settings.inventorySlot = SimpleLayout.ObjectField(settings.inventorySlot, HeroKitCommon.GetWidthForField(65));
            if (settings.inventorySlot == null)
            {
                HeroKitCommon.RefreshHeroSettings();
            }
            SimpleLayout.EndVertical();
            SimpleLayout.Space(distance);

            SimpleLayout.BeginVertical(Box.StyleB);
            SimpleLayout.Label("Journal Menu");
            settings.journalMenu = SimpleLayout.ObjectField(settings.journalMenu, HeroKitCommon.GetWidthForField(65));
            if (settings.journalMenu == null)
            {
                HeroKitCommon.RefreshHeroSettings();
            }
            SimpleLayout.Label("Journal Item");
            settings.journalItem = SimpleLayout.ObjectField(settings.journalItem, HeroKitCommon.GetWidthForField(65));
            if (settings.journalItem == null)
            {
                HeroKitCommon.RefreshHeroSettings();
            }
            SimpleLayout.Label("Journal Slot");
            settings.journalSlot = SimpleLayout.ObjectField(settings.journalSlot, HeroKitCommon.GetWidthForField(65));
            if (settings.journalSlot == null)
            {
                HeroKitCommon.RefreshHeroSettings();
            }
            SimpleLayout.EndVertical();
            SimpleLayout.Space(distance);

            SimpleLayout.BeginVertical(Box.StyleB);
            SimpleLayout.Label("Options Menu");
            settings.optionsMenu = SimpleLayout.ObjectField(settings.optionsMenu, HeroKitCommon.GetWidthForField(65));
            if (settings.optionsMenu == null)
            {
                HeroKitCommon.RefreshHeroSettings();
            }
            SimpleLayout.EndVertical();
            SimpleLayout.Space(distance);

            SimpleLayout.BeginVertical(Box.StyleB);
            SimpleLayout.Label("Save Menu");
            settings.saveMenu = SimpleLayout.ObjectField(settings.saveMenu, HeroKitCommon.GetWidthForField(65));
            if (settings.saveMenu == null)
            {
                HeroKitCommon.RefreshHeroSettings();
            }
            SimpleLayout.Label("Save Slot");
            settings.saveSlot = SimpleLayout.ObjectField(settings.saveSlot, HeroKitCommon.GetWidthForField(65));
            if (settings.saveSlot == null)
            {
                HeroKitCommon.RefreshHeroSettings();
            }
            SimpleLayout.EndVertical();
            SimpleLayout.Space(distance);

            SimpleLayout.BeginVertical(Box.StyleB);
            SimpleLayout.Label("Start Menu");
            settings.startMenu = SimpleLayout.ObjectField(settings.startMenu, HeroKitCommon.GetWidthForField(65));
            if (settings.startMenu == null)
            {
                HeroKitCommon.RefreshHeroSettings();
            }
            SimpleLayout.EndVertical();
            SimpleLayout.Space(distance);
        }
Exemple #16
0
        /// <summary>
        /// Hero Object = A hero object attached to a game object in a scene.
        /// </summary>
        /// <typeparam name="T">The type of data for the action field.</typeparam>
        /// <param name="data">The data for the action field.</param>
        /// <returns>The data for the action field.</returns>
        public static T GetHeroObjectInScene <T>(T data) where T : ITargetHeroObject
        {
            GameObject    go       = null;
            HeroKitObject hkoField = null;

            // if there is no game object attached to action, do this here...
            if (data.heroGUID == 0)
            {
                hkoField = SimpleLayout.ObjectField <HeroKitObject>(hkoField, 300, true);
                if (hkoField != null)
                {
                    go = hkoField.gameObject;
                }
            }

            // if a game object was attached to action, update fields here...
            if (data.heroGUID != 0)
            {
                HeroKitObject hko = HeroKitDatabase.GetHeroKitObject(data.heroGUID);
                if (hko != null)
                {
                    go = hko.gameObject;
                }

                oldGUID = data.heroGUID;
                newGUID = data.heroGUID;

                SimpleLayout.Space(5);
                SimpleLayout.Button(" [X] " + data.objectName, new UnityAction <T>(DeleteGameObject), data, Button.StyleB, 205);

                if (oldGUID != newGUID)
                {
                    data.heroGUID         = newGUID;
                    data.objectName       = "";
                    data.targetHeroObject = null;
                    go = null;
                }
            }

            // if there is a game object attached to the action field, populate it here
            if (go != null)
            {
                HeroKitObject hko = go.GetComponent <HeroKitObject>();
                if (hko == null)
                {
                    Debug.LogError("Game Object can't be added because it doesn't have a Hero Kit Object component. Add this component and re-add the game object.");
                    return(data);
                }

                data.heroGUID   = hko.heroGUID;
                data.objectName = go.name;

                // get the hero kit objects in the open scene(s)
                HeroKitObject[] heroKitObjects = Resources.FindObjectsOfTypeAll <HeroKitObject>();

                // get the gameobject that has the GUID we need
                for (int i = 0; i < heroKitObjects.Count(); i++)
                {
                    if (heroKitObjects[i].heroGUID == data.heroGUID)
                    {
                        data.targetHeroObject = heroKitObjects[i].heroObject;
                        break;
                    }
                }
            }
            else
            {
                data.targetHeroObject = null;
            }

            return(data);
        }
Exemple #17
0
        /// <summary>
        /// Choose the rigidbody for object in this state.
        /// </summary>
        /// <param name="is2D">If we are working with 2D visuals, set this to true.</param>
        private static void DrawRigidbodyForState(bool is2D = false)
        {
            // display the collider type
            SimpleLayout.BeginVertical(Box.StyleB);
            string rigidBodyName = (is2D) ? "2D" : "3D";

            SimpleLayout.Label("Rigidbody for " + rigidBodyName + " Object (drag prefab that contains the rigidbody here):");

            string[] rigidbodyOptions = null;
            // 3d rigidbody options
            if (!is2D)
            {
                rigidbodyOptions = new string[] { "Default Rigidbody", "Custom Rigidbody", "No Rigidbody", "Heavy Rigidbody" }
            }
            ;
            // 2d rigidbody options
            else
            {
                rigidbodyOptions = new string[] { "Platformer Rigidbody", "RPG Rigidbody", "Custom Rigidbody",
                                                  "No Rigidbody", "Platformer Heavy Rigidbody", "RPG Heavy Rigidbody" }
            };

            stateBlock.heroVisuals.rigidbodyType = new GenericListField(rigidbodyOptions).SetValues(stateBlock.heroVisuals.rigidbodyType, 0);

            // draw 3D rigidbody
            if (!is2D)
            {
                switch (stateBlock.heroVisuals.rigidbodyType)
                {
                case 0:     // not set
                    break;

                case 1:     // use default rigidbody
                    GameObject template = Resources.Load <GameObject>("Hero Templates/Components/" + "HeroKit 3D Rigidbody");
                    stateBlock.heroVisuals.rigidbody = (template != null) ? template.GetComponent <Rigidbody>() : null;
                    break;

                case 2:     // use custom rigidbody
                    stateBlock.heroVisuals.rigidbody = SimpleLayout.ObjectField(stateBlock.heroVisuals.rigidbody);
                    break;

                case 3:     // no rigidbody
                    stateBlock.heroVisuals.rigidbody = null;
                    break;

                case 4:     // heavy rigidbody
                    GameObject templateHeavy = Resources.Load <GameObject>("Hero Templates/Components/" + "HeroKit 3D Heavy Rigidbody");
                    stateBlock.heroVisuals.rigidbody = (templateHeavy != null) ? templateHeavy.GetComponent <Rigidbody>() : null;
                    break;
                }
            }

            // draw 2D rigidbody
            else
            {
                switch (stateBlock.heroVisuals.rigidbodyType)
                {
                case 0:     // not set
                    break;

                case 1:     // use platformer rigidbody
                    GameObject template = Resources.Load <GameObject>("Hero Templates/Components/" + "HeroKit 2D Platformer Rigidbody");
                    stateBlock.heroVisuals.rigidbody2D = (template != null) ? template.GetComponent <Rigidbody2D>() : null;
                    break;

                case 2:     // use rpg rigidbody
                    GameObject templateRPG = Resources.Load <GameObject>("Hero Templates/Components/" + "HeroKit 2D RPG Rigidbody");
                    stateBlock.heroVisuals.rigidbody2D = (templateRPG != null) ? templateRPG.GetComponent <Rigidbody2D>() : null;
                    break;

                case 3:     // use custom rigidbody
                    stateBlock.heroVisuals.rigidbody2D = SimpleLayout.ObjectField(stateBlock.heroVisuals.rigidbody2D);
                    break;

                case 4:     // no rigidbody
                    stateBlock.heroVisuals.rigidbody2D = null;
                    break;

                case 5:     // use platformer heavy rigidbody
                    GameObject templateHeavy = Resources.Load <GameObject>("Hero Templates/Components/" + "HeroKit 2D Heavy Platformer Rigidbody");
                    stateBlock.heroVisuals.rigidbody2D = (templateHeavy != null) ? templateHeavy.GetComponent <Rigidbody2D>() : null;
                    break;

                case 6:     // use rpg heavy rigidbody
                    GameObject templateRPGHeavy = Resources.Load <GameObject>("Hero Templates/Components/" + "HeroKit 2D Heavy RPG Rigidbody");
                    stateBlock.heroVisuals.rigidbody2D = (templateRPGHeavy != null) ? templateRPGHeavy.GetComponent <Rigidbody2D>() : null;
                    break;
                }
            }

            SimpleLayout.EndVertical();
        }
    }
        // --------------------------------------------------------------
        // Action Fields
        // --------------------------------------------------------------

        /// <summary>
        /// Get a value from a unity object field.
        /// This is for a field that contains Value, Variable, Property, Global.
        /// </summary>
        /// <typeparam name="T">The type of unity object.</typeparam>
        /// <param name="title">Title for action field.</param>
        /// <param name="actionParams">Action field parameters.</param>
        /// <param name="actionField">Action field.</param>
        /// <param name="titleToLeft">Show the title on the left?</param>
        /// <returns></returns>
        public static T BuildFieldA <T>(string title, HeroActionParams actionParams, HeroActionField actionField, bool titleToLeft = false) where T : Object
        {
            // create the fields
            UnityObjectFieldData data = CreateFieldData(title, actionField, actionParams.heroObject);

            //-----------------------------------------
            // Display this title above the field
            //-----------------------------------------
            if (data.title != "" && !titleToLeft)
            {
                SimpleLayout.Label(data.title);
            }
            SimpleLayout.BeginHorizontal();
            if (data.title != "" && titleToLeft)
            {
                SimpleLayout.Label(data.title);
            }

            //-----------------------------------------
            // Get the type of field you want to work with.
            //-----------------------------------------
            data.fieldType = new HeroField.ValueTypeField().SetValues(data.fieldType, 0);

            //-----------------------------------------
            // Get the type of game object we are working with
            // Option 1: This game object (game object that this hero object is attached to)
            // Option 2: Another game object (another game object in the scene that has a hero object attached to it)
            //-----------------------------------------
            if (data.fieldType == 2 || data.fieldType == 3)
            {
                data = ActionCommon.GetTargetHeroObject(data);
            }

            //-----------------------------------------
            // Get the integer list you want to work with.
            // The integer list is in hero object editor > Variables
            //-----------------------------------------
            // if this is a field, draw field (1=value)
            if (data.fieldType == 1)
            {
                data.fieldValue = SimpleLayout.ObjectField(data.fieldValue as T, HeroKitCommon.GetWidthForField(135));
                SetScene(ref data);
            }

            // if this is a list, draw ints (2=variables, 3=properties)
            if (data.fieldType != 1)
            {
                data = SetPropertyID(data, -1);
                List <UnityObjectField> items = GetItemsFromList(data, -1);
                data = BuildItemFieldList(data, items);
            }

            //-----------------------------------------
            // assign values back to hero object fields
            //-----------------------------------------
            actionField.ints[0]         = data.objectType;
            actionField.ints[1]         = data.objectID;
            actionField.ints[2]         = data.fieldID;
            actionField.ints[3]         = data.fieldType;
            actionField.ints[4]         = data.heroGUID;
            actionField.ints[6]         = data.propertyID;
            actionField.heroObjects[0]  = data.targetHeroObject;
            actionField.strings[0]      = data.objectName;
            actionField.unityObjects[0] = data.fieldValue;
            actionField.ints[5]         = data.sceneID;
            actionField.strings[1]      = data.sceneName;

            //-----------------------------------------
            // Visual stuff
            //-----------------------------------------
            SimpleLayout.Space();
            SimpleLayout.EndHorizontal();

            return(data.fieldValue as T);
        }