Beispiel #1
0
 public int DeterminePriceForResource(ResourceManager.Resource resource)
 {
     return(resource.price);
 }
    public override void OnInspectorGUI()
    {
        serializedObject.Update();
        var oldDisplayType = displayType;

        EditorGUILayout.BeginHorizontal();
        EditorGUILayout.LabelField("Resource Manager");
        EditorGUILayout.EndHorizontal();
        EditorGUILayout.BeginHorizontal();
        EditorGUILayout.LabelField("The #1 choice for ALL ShellCore asset injections!");
        EditorGUILayout.EndHorizontal();
        EditorGUI.BeginChangeCheck();
        EditorGUILayout.PropertyField(resourcePack, new GUIContent("Resource pack: "));
        if (EditorGUI.EndChangeCheck())
        {
            manager.GenerateSegmentedList(ResourcesByType.all);
            segmentedBuiltIns = serializedObject.FindProperty("segmentedBuiltIns");
        }
        if (manager.resourcePack == null)
        {
            serializedObject.ApplyModifiedProperties();
            return;
        }
        EditorGUILayout.BeginHorizontal();
        manager.fieldID = EditorGUILayout.TextField("Resource ID:", IDField.stringValue) as string;
        EditorGUILayout.EndHorizontal();
        EditorGUILayout.BeginHorizontal();
        manager.newObject = EditorGUILayout.ObjectField("Resource Object:",
                                                        ObjectField.objectReferenceValue, typeof(Object), true) as Object;
        EditorGUILayout.EndHorizontal();
        EditorGUILayout.BeginHorizontal();
        GUI.SetNextControlName("add");
        if (GUILayout.Button("Add/Modify Resource by ID!"))
        {
            ResourceManager.Resource resource = new ResourceManager.Resource();
            resource.ID  = manager.fieldID;
            resource.obj = manager.newObject;
            for (int i = 0; i < manager.resourcePack.resources.Count; i++)
            {
                if (manager.resourcePack.resources[i].ID == manager.fieldID)
                {
                    manager.resourcePack.resources[i] = resource;
                    Debug.Log(manager.fieldID);
                    state = EditorState.successModify;
                    break;
                }
            }
            if (state != EditorState.successModify)
            {
                manager.resourcePack.resources.Add(resource);
                state = EditorState.successAdd;
            }
            manager.GenerateSegmentedList(displayType);
            IDField.stringValue = null;
            manager.fieldID     = null;
            manager.newObject   = ObjectField.objectReferenceValue = null;
            GUI.FocusControl("add");
            serializedObject.Update();
        }
        EditorGUILayout.EndHorizontal();
        EditorGUILayout.BeginHorizontal();
        GUI.SetNextControlName("delete");
        if (GUILayout.Button("Delete Resource by ID!"))
        {
            state = EditorState.failedToFind;
            foreach (ResourceManager.Resource res in manager.resourcePack.resources)
            {
                if (res.ID == manager.fieldID)
                {
                    manager.resourcePack.resources.Remove(res);
                    manager.fieldID   = IDField.stringValue = "";
                    manager.newObject = ObjectField.objectReferenceValue = null;
                    manager.GenerateSegmentedList(displayType);
                    state = EditorState.successDelete;
                    GUI.FocusControl("delete");
                    serializedObject.Update();
                    break;
                }
            }
        }
        EditorGUILayout.EndHorizontal();
        EditorGUILayout.BeginHorizontal();
        if (GUILayout.Button("Find Resource by ID!"))
        {
            state = EditorState.failedToFind;
            foreach (ResourceManager.Resource res in manager.resourcePack.resources)
            {
                if (res.ID == manager.fieldID)
                {
                    manager.newObject = res.obj;
                    state             = EditorState.successFind;
                    break;
                }
            }
            serializedObject.Update();
        }
        EditorGUILayout.EndHorizontal();
        EditorGUILayout.BeginHorizontal();
        if (GUILayout.Button("Export all to ResourcePack"))
        {
            ResourcePack pack = CreateInstance <ResourcePack>();
            pack.resources = new List <ResourceManager.Resource>();
            foreach (ResourceManager.Resource res in manager.resourcePack.resources)
            {
                pack.resources.Add(res);
            }

            string path = "Assets/DefaultResources.asset";
            AssetDatabase.CreateAsset(pack, path);
            AssetDatabase.SaveAssets();
            AssetDatabase.Refresh();
        }
        EditorGUILayout.EndHorizontal();

        EditorGUILayout.BeginHorizontal();
        GUI.SetNextControlName("CreateJSON");
        if (GUILayout.Button("Create JSON file"))
        {
            string type = null;
            if (manager.newObject is EntityBlueprint)
            {
                type = "entities";
            }
            else if (manager.newObject is PartBlueprint)
            {
                type = "parts";
            }
            if (type != null)
            {
                // Create JSON
                File.WriteAllText(manager.newObject.name + ".json", JsonUtility.ToJson(manager.newObject));

                // Add path and ID to resource data
                if (!File.Exists("ResourceData.txt"))
                {
                    File.Create("ResourceData.txt").Close();
                }

                List <string> lines        = new List <string>(File.ReadAllLines("ResourceData.txt"));
                bool          sectionFound = false;
                for (int i = 0; i < lines.Count; i++)
                {
                    if (lines[i].StartsWith(type))
                    {
                        lines.Insert(i + 1, manager.fieldID + ":" + manager.newObject.name + ".json");
                        sectionFound = true;
                        break;
                    }
                }
                if (!sectionFound)
                {
                    lines.Add(type + ":");
                    lines.Add(manager.fieldID + ":" + manager.newObject.name + ".json");
                }

                File.WriteAllLines("ResourceData.txt", lines.ToArray());

                manager.fieldID   = null;
                manager.newObject = ObjectField.objectReferenceValue = null;
            }
            else
            {
                Debug.Log("Can't serialize that asset to json format!");
            }
        }
        EditorGUILayout.EndHorizontal();

        EditorGUILayout.BeginHorizontal();
        displayType = (ResourcesByType)EditorGUILayout.EnumPopup("Resources by type: ", displayType);
        if (displayType != oldDisplayType)
        {
            manager.GenerateSegmentedList(displayType);
        }

        EditorGUILayout.EndHorizontal();
        EditorGUILayout.BeginHorizontal();
        EditorGUILayout.PropertyField(segmentedBuiltIns, new GUIContent("Built-ins by type"), true);
        EditorGUILayout.EndHorizontal();
        switch (state)
        {
        case EditorState.failedToFind:
            EditorGUILayout.HelpBox("Failed to find a resource with the specified ID!", MessageType.Warning);
            break;

        case EditorState.successAdd:
            EditorGUILayout.HelpBox("Successfully added resource!", MessageType.Info);
            break;

        case EditorState.successDelete:
            EditorGUILayout.HelpBox("Successfully deleted resource!", MessageType.Info);
            break;

        case EditorState.successModify:
            EditorGUILayout.HelpBox("Successfully modified resource!", MessageType.Info);
            break;

        case EditorState.successFind:
            EditorGUILayout.HelpBox("Successfully found resource!", MessageType.Info);
            break;

        default:
            break;
        }

        serializedObject.ApplyModifiedProperties();
    }
Beispiel #3
0
 public bool DetermineImportanceForResource(ResourceManager.Resource resource)
 {
     return(false);            // TODO This needs to be implemented once the originLocation is properly implemented (see above)
 }