Smart way to populate Unity GameObjects to Inputs on HoudiniAssetOTL (DigitalAsset)

   2588   1   0
User Avatar
Member
7 posts
Joined: Feb. 2015
Offline
Hi!

(100 is just a random number, it need to be dynamic)

So I got 100 GameObjects in Unity Editor Scene with tag “Collider”. I have made a Digital Asset where there is a merge inside and 100 inputs for all of them.



Instead of drag and drop 100 times that also will happen multiple times I want to populate it with code. I'm almost there I think. It seems like I need to convert my GameObject to HAPI_Transform. I'm stuck.

Does anyone have any idea please? :-D

this is c# code in Unity

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
using Houdini;

public class CollectTagColliders : EditorWindow
{
    public static CollectTagColliders curColliderWindow;
   // public static GameObject curDGA_ColliderAsset;
    public GameObject curColliderParent;
    public static GameObject[] sceneGameObjects;


    public static GameObject curObj;
    public static HoudiniApiAssetAccessor curAccessor = null;
    public static HoudiniAssetOTL asset;
    public static HoudiniAssetOTL curOTL;
    public static HoudiniParms curParms;
    public static HAPI_ParmInfo[] parmInfos;




    [MenuItem("Spelprojekt 8/CollectColliders",false,7)]
	public static void InitWindow ()
    {
        curColliderWindow = (CollectTagColliders)EditorWindow.GetWindow<CollectTagColliders>();
        GUIContent titelcontent = new GUIContent("ColliderTool");

        //get all scene GameObjects with tag Collider
        sceneGameObjects = GameObject.FindGameObjectsWithTag("Collider");

        
    }
    private void OnGUI()
    {

        if (sceneGameObjects.Length == 0)
        {
            GUILayout.Label("There is no Collider Tags in scene");
        }
        else
        {
            if (GUILayout.Button("Print All Colliders in Debug", GUILayout.Height(40f)))
            {
                for (int i = 0; i < sceneGameObjects.Length; i++)
                {
                    Debug.Log(sceneGameObjects[i].name + "  index--> " + i);
                }
            }
            if (GUILayout.Button("Print All DGA params", GUILayout.Height(40f)))
            {
                PlaceColliderToScene();
            }
        }
    }

    static void PlaceColliderToScene()
    {
        string assetPath = Application.dataPath + "Assets/DigitalAssets/B_addon_Collider_Parent.otl";
        curObj = new GameObject("B_addon_Collider_Parent");
        asset = curObj.AddComponent<HoudiniAssetOTL>();
        curAccessor = HoudiniApiAssetAccessor.getAssetAccessor(curObj);
        asset.prAssetType = HoudiniAsset.AssetType.TYPE_OTL;
//        asset.prAssetType = HoudiniAsset.AssetType.TYPE_INPUT;
        asset.prAssetPath = assetPath;

        asset.buildAll();

        curOTL = (HoudiniAssetOTL)asset.GetComponent<HoudiniAssetOTL>();
        Debug.Log(curOTL.prObjectTransforms.Length + " geo count!! ");

        Debug.Log(curOTL.prGeoInputCount + " geo total slot count!! ");

        curParms = asset.prParms;
        parmInfos = curParms.prParms;


        for (int i = 0; i < sceneGameObjects.Length; i++)
        {
            curOTL.prObjectTransforms[i] = sceneGameObjects[i];
        }

        Selection.activeObject = curObj;

    }


}
User Avatar
Member
7 posts
Joined: Feb. 2015
Offline
So I solved it to tag all the collider objects and with this code populate the list “prUpStreamGeoObjects”

static void PlaceColliderToScene()
{
//get all colliders in scene
sceneGameObjects = GameObject.FindGameObjectsWithTag(“Collider”);
curObj = Selection.activeObject as GameObject;

curOTL = curObj.GetComponent<HoudiniAssetOTL>();

for (int i = 0; i < sceneGameObjects.Length; i++)
{
curOTL.prUpStreamGeoObjects = sceneGameObjects;

}
Selection.activeObject = curObj;
}
  • Quick Links