Esempio n. 1
0
    private void UpdateCharacters()
    {
        if (Characters.Length != 128)
        {
            Characters = new Character[128];
        }
        for (int i = 0; i < 128; i++)
        {
            Character             character  = Characters[i];
            Object[]              allAssets  = UnityEditor.AssetDatabase.LoadAllAssetsAtPath(FontFolder + "/" + i + ".asset");
            NPVoxCubeSimplifier[] simplifier = NPipelineUtils.GetByType <NPVoxCubeSimplifier>(allAssets);
            if (simplifier.Length == 1)
            {
//                Debug.Log("found character: " + simplifier[0]);
                character.material = simplifier[0].GetAtlasMaterial();
                character.mesh     = simplifier[0].GetProduct();
                if (simplifier[0].InputMeshFactory)
                {
                    character.VoxelSize = simplifier[0].InputMeshFactory.VoxelSize;
                    character.Size      = simplifier[0].InputMeshFactory.GetVoxModel().Size;
                }
            }
            else
            {
                character.mesh     = null;
                character.material = null;
            }

            Characters[i] = character;
        }
    }
 static void MenuInvalidateAndImportSelectedDeep()
 {
     foreach (UnityEngine.Object target in Selection.objects)
     {
         NPipeIImportable[] allImportables = NPipelineUtils.FindOutputPipes(NPipelineUtils.GetByType <NPipeIImportable>(target));
         NPipelineUtils.InvalidateAll(allImportables, true);
         EditorUtility.SetDirty(target as UnityEngine.Object);
     }
     AssetDatabase.SaveAssets();
 }
    override public void OnAssetCreated()
    {
        base.OnAssetCreated();
        NPVoxMeshOutput output = NPipelineUtils.GetByType <NPVoxMeshOutput>(NPVoxUtils.GetTemplatePipeline())[0];

        MeshFactory              = (NPVoxMeshOutput)output.Clone();
        MeshFactory.StorageMode  = NPipeStorageMode.RESOURCE_CACHE;
        MeshFactory.Input        = null;
        MeshFactory.InstanceName = "_TEMPLATE_";
        NPipelineUtils.CreateAttachedPipe(UnityEditor.AssetDatabase.GetAssetPath(this), MeshFactory);
        UnityEditor.AssetDatabase.SaveAssets();
    }
Esempio n. 4
0
    static void MakeVoxPrefabs()
    {
        var path = EditorUtility.SaveFolderPanel(
            "Select target folder for the generated Prefabs ",
            "Prefabs",
            "Select Path for the generated Prefabs");

        path = path.Remove(0, path.LastIndexOf("Assets"));

        if (path.Length != 0)
        {
            Object[] SelectedObjects = Selection.objects;
            int      generatedCount  = 0;
            foreach (Object o in SelectedObjects)
            {
                NPipeContainer container = o as NPipeContainer;
                if (!container)
                {
                    continue;
                }
                NPVoxMeshOutput[] output = NPipelineUtils.GetByType <NPVoxMeshOutput>(container);
                foreach (NPVoxMeshOutput pipe in output)
                {
                    NPVoxMeshInstance instance = pipe.Instatiate().GetComponent <NPVoxMeshInstance>();

                    string prefabPath = Path.Combine(path, instance.name) + ".prefab";

                    PrefabUtility.CreatePrefab(prefabPath, instance.gameObject);
                    GameObject.DestroyImmediate(instance.gameObject);
                    generatedCount++;
                }
            }

            AssetDatabase.SaveAssets();
            AssetDatabase.Refresh();

            if (generatedCount > 0)
            {
                Debug.Log("Generated " + generatedCount + " Prefabs");
            }
            else
            {
                Debug.LogWarning("No NPVoxMetadata selected");
            }
        }
    }
Esempio n. 5
0
    protected bool DrawPipelineElements()
    {
        //==================================================================================================================================
        // setup colors
        //==================================================================================================================================
        normalStyle = new GUIStyle((GUIStyle)"helpbox");
        normalStyle.normal.textColor = Color.black;
        normalStyle.fontStyle        = FontStyle.Normal;
        boldStyle = new GUIStyle((GUIStyle)"helpbox");
        boldStyle.normal.textColor = Color.black;
        boldStyle.fontStyle        = FontStyle.Bold;
        thisContainerColor         = new Color(0.8f, 1.0f, 0.6f);
        thisContainerMultiColor    = new Color(0.8f, 0.6f, 1.0f);

        string assetPath = AssetDatabase.GetAssetPath(target);

        NPipeIImportable[] allImportables = NPipelineUtils.GetByType <NPipeIImportable>(target);
        NPipeIImportable[] outputPipes    = NPipelineUtils.FindOutputPipes(allImportables);

        //==================================================================================================================================
        // Tool Buttons (Select Me, Invalidation)
        //==================================================================================================================================

        GUILayout.BeginHorizontal();
        if (GUILayout.Button("Select Me"))
        {
            Selection.objects = this.targets;
        }

        GUILayout.BeginHorizontal();
        if (GUILayout.Button("Invalidate & Reimport All"))
        {
            NPipelineUtils.InvalidateAndReimportAll(targets);
        }
        if (GUILayout.Button("Invalidate & Reimport All Deep"))
        {
            NPipelineUtils.InvalidateAndReimportAllDeep(targets);
        }
        GUILayout.EndHorizontal();
        GUILayout.EndHorizontal();

        //==================================================================================================================================
        // Single Instance Mode Only for Lazyness Tool Buttons (Deleta all Payload, Instantiate)
        //==================================================================================================================================

        if (!this.isMultiInstance)
        {
            if (GUILayout.Button("Delete all Payload"))
            {
                UnityEngine.Object[] allObjects = AssetDatabase.LoadAllAssetsAtPath(assetPath);
                foreach (UnityEngine.Object obj in allObjects)
                {
                    if (!(obj is NPipeIImportable) && !(obj is NPipeContainer))
                    {
                        DestroyImmediate(obj, true);
                    }
                }
                EditorUtility.SetDirty(target);
            }

            foreach (NPipeIImportable imp in allImportables)
            {
                if (imp is NPipeIInstantiable && GUILayout.Button("Instantiate " + imp.GetInstanceName() + " (" + imp.GetTypeName() + ")"))
                {
                    ((NPipeIInstantiable)imp).Instatiate();
                }
            }
        }

        //==================================================================================================================================
        // Draw Pipelines
        //==================================================================================================================================
        {
            GUILayout.Space(10f);

            // headline
            GUILayout.Label(string.Format("Pipelines", allImportables.Length), EditorStyles.boldLabel);

            // pipelines
            GUILayout.BeginHorizontal();
            HashSet <NPipeIImportable> visited = new HashSet <NPipeIImportable>();
            foreach (NPipeIImportable iimp in outputPipes)
            {
                DrawPipelineElements(assetPath, iimp, visited, false);
            }

            GUI.backgroundColor = isMultiInstance ? thisContainerMultiColor : thisContainerColor;

            if (!isMultiInstance)
            {
                GUILayout.BeginHorizontal();
                GUILayout.Label("Add: ");
                {
                    GUILayout.BeginVertical();
                    foreach (Type factoryType in NPipeReflectionUtil.GetAllTypesWithAttribute(typeof(NPipeStartingAttribute)))
                    {
                        NPipeStartingAttribute attr = (NPipeStartingAttribute)factoryType.GetCustomAttributes(typeof(NPipeStartingAttribute), true)[0];
                        if (attr.attached && GUILayout.Button(attr.name))
                        {
                            NPipelineUtils.CreateAttachedPipe(assetPath, factoryType);
                        }
                    }

                    List <System.Type> allTypes  = new List <System.Type>(NPipeReflectionUtil.GetAllTypesWithAttribute(typeof(NPipeAppendableAttribute)));
                    List <string>      allLabels = new List <string>();
                    allLabels.Add("Other ...");
                    foreach (Type factoryType in allTypes)
                    {
                        NPipeAppendableAttribute attr = (NPipeAppendableAttribute)factoryType.GetCustomAttributes(typeof(NPipeAppendableAttribute), true)[0];
                        allLabels.Add(attr.name);
                    }
                    int selection = EditorGUILayout.Popup(0, allLabels.ToArray());
                    if (selection > 0)
                    {
                        NPipelineUtils.CreateAttachedPipe(assetPath, allTypes[selection - 1]);
                    }
                    GUILayout.EndVertical();
                }
                GUILayout.EndHorizontal();
            }
            GUILayout.EndHorizontal();
        }

        drawPipeEditor(assetPath);

        return(false);
    }