public static void ShowWindow(SelectionResultHandler selectionHandler, System.Type selectionType)
        {
            bool   bUtility = false;
            bool   bFocus   = true;
            string title    = "Input Selection";

            HEU_SelectionWindow window = EditorWindow.GetWindow <HEU_SelectionWindow>(bUtility, title, bFocus);

            window.autoRepaintOnSceneChange = true;
            window._selectionHandler        = selectionHandler;
            window._selectionType           = selectionType;
        }
Example #2
0
        private static void DrawSelectionWindow(HEU_InputNode.InputObjectType inputObjectType, HEU_InputNode inputNode)
        {
            using (var hs1 = new EditorGUILayout.HorizontalScope())
            {
                if (GUILayout.Button(new GUIContent("Selection Window", "Use a custom window to select the objects from the Hierarchy.")))
                {
                    if (HEU_InputNode.GetInternalObjectType(inputObjectType) == HEU_InputNode.InternalObjectType.HDA)
                    {
                        HEU_SelectionWindow.ShowWindow(HandleSelectedObjectsForInputHDAs, typeof(HEU_HoudiniAssetRoot), inputNode);
                    }
                    else if (inputObjectType == HEU_InputNode.InputObjectType.TERRAIN)
                    {
                        HEU_SelectionWindow.ShowWindow(HandleSelectedObjectsForInputObjects, typeof(Terrain), inputNode);
                    }
                    else if (inputObjectType == HEU_InputNode.InputObjectType.BOUNDING_BOX)
                    {
                        HEU_SelectionWindow.ShowWindow(HandleSelectedObjectsForInputObjects, typeof(HEU_BoundingVolume), inputNode);
                    }
                    else if (inputObjectType == HEU_InputNode.InputObjectType.TILEMAP)
                    {
                        HEU_SelectionWindow.ShowWindow(HandleSelectedObjectsForInputObjects, typeof(Tilemap), inputNode);
                    }
                    else
                    {
                        HEU_SelectionWindow.ShowWindow(HandleSelectedObjectsForInputObjects, typeof(GameObject), inputNode);
                    }
                }

                if (!inputNode._usingSelectFromHierarchy)
                {
                    string title             = "Select from Hierarchy (Locks Inspector)";
                    float  shortenLength     = 420;
                    float  reallyShortLength = 320;

                    float screenWidth = Screen.width;
                    if (screenWidth < reallyShortLength)
                    {
                        title = "From Hierarchy";
                    }
                    else if (screenWidth < shortenLength)
                    {
                        title = "Select from Hierarchy";
                    }

                    if (GUILayout.Button(new GUIContent(title, "Locks the inspector and so you can select GameObjects from the Hierarchy. Once select, press Use Current Selection to add the specified objects as inputs.")))
                    {
                        SetInspectorLock(true);
                        inputNode._usingSelectFromHierarchy = true;
                    }
                }
                else
                {
                    if (GUILayout.Button("Use Current Selection"))
                    {
                        SetInspectorLock(false);
                        inputNode._usingSelectFromHierarchy = false;

                        GameObject[]      selection       = Selection.gameObjects;
                        List <GameObject> filteredObjects = new List <GameObject>(selection);


                        filteredObjects = filteredObjects.Filter((GameObject obj) => {
                            if (obj == null)
                            {
                                return(false);
                            }

                            bool result = true;

                            if (HEU_InputNode.GetInternalObjectType(inputObjectType) == HEU_InputNode.InternalObjectType.HDA &&
                                obj.GetComponent <HEU_HoudiniAssetRoot>() == null)
                            {
                                result = false;
                            }
                            else if (inputObjectType == HEU_InputNode.InputObjectType.TERRAIN &&
                                     obj.GetComponent <Terrain>() == null)
                            {
                                result = false;
                            }
                            else if (inputObjectType == HEU_InputNode.InputObjectType.BOUNDING_BOX &&
                                     obj.GetComponent <HEU_BoundingVolume>() == null)
                            {
                                result = false;
                            }
                            else if (inputObjectType == HEU_InputNode.InputObjectType.TILEMAP &&
                                     obj.GetComponent <Tilemap>() == null)
                            {
                                result = false;
                            }

                            if (result == false)
                            {
                                HEU_Logger.LogWarning("Houdini GameObject selection: " + obj.name + " filtered out due to invalid type!");
                                return(false);
                            }

                            return(true);
                        });

                        if (HEU_InputNode.GetInternalObjectType(inputObjectType) == HEU_InputNode.InternalObjectType.HDA)
                        {
                            HandleSelectedObjectsForInputHDAs(filteredObjects.ToArray(), inputNode);
                        }
                        else
                        {
                            HandleSelectedObjectsForInputObjects(filteredObjects.ToArray(), inputNode);
                        }

                        // Populate input cache if modified.
                        if (inputNode._uiCache == null)
                        {
                            PopulateCache(inputNode);
                        }

                        if (inputNode.ParentAsset && inputNode.ParentAsset.RootGameObject)
                        {
                            // Select this gameObject so it doesn't jump to the last selection as soon as it unlocks.
                            Selection.activeGameObject = inputNode.ParentAsset.RootGameObject.gameObject;
                        }
                    }
                }
            }
        }
        /// <summary>
        /// Draw the UI for the given input node
        /// </summary>
        /// <param name="inputNode"></param>
        public static void EditorDrawInputNode(HEU_InputNode inputNode)
        {
            int plusButtonWidth = 20;

            //GUIStyle boldLabelStyle = new GUIStyle(EditorStyles.boldLabel);
            //boldLabelStyle.alignment = TextAnchor.UpperLeft;

            GUIContent inputTypeLabel = new GUIContent("Input Type");

            GUIContent translateLabel = new GUIContent("    Translate");
            GUIContent rotateLabel    = new GUIContent("    Rotate");
            GUIContent scaleLabel     = new GUIContent("    Scale");

            PopulateCache(inputNode);

            EditorGUI.BeginChangeCheck();

            EditorGUILayout.BeginVertical(EditorStyles.helpBox);

            string labelName = inputNode.LabelName;

            if (!string.IsNullOrEmpty(labelName))
            {
                EditorGUILayout.LabelField(labelName);
            }

            EditorGUI.indentLevel++;

            HEU_InputNode.InputObjectType inputObjectType             = (HEU_InputNode.InputObjectType)inputNode._uiCache._inputObjectTypeProperty.intValue;
            HEU_InputNode.InputObjectType userSelectedInputObjectType = (HEU_InputNode.InputObjectType)EditorGUILayout.EnumPopup(inputTypeLabel, inputObjectType);
            if (userSelectedInputObjectType != inputObjectType)
            {
                SerializedProperty pendingInputObjectTypeProperty = HEU_EditorUtility.GetSerializedProperty(inputNode._uiCache._inputNodeSerializedObject, "_pendingInputObjectType");
                if (pendingInputObjectTypeProperty != null)
                {
                    pendingInputObjectTypeProperty.intValue = (int)userSelectedInputObjectType;
                }
            }
            else
            {
                EditorGUILayout.PropertyField(inputNode._uiCache._keepWorldTransformProperty);
                EditorGUILayout.PropertyField(inputNode._uiCache._packBeforeMergeProperty);

                if (inputObjectType == HEU_InputNode.InputObjectType.HDA)
                {
                    SerializedProperty inputAssetsProperty = inputNode._uiCache._inputAssetsProperty;
                    if (inputAssetsProperty != null)
                    {
                        int  inputCount    = inputAssetsProperty.arraySize;
                        bool bSkipElements = false;

                        HEU_EditorUI.DrawSeparator();

                        EditorGUILayout.LabelField(string.Format("{0} input objects", inputCount));

                        using (var hs1 = new EditorGUILayout.HorizontalScope())
                        {
                            if (GUILayout.Button("Add Slot"))
                            {
                                inputAssetsProperty.InsertArrayElementAtIndex(inputCount);

                                bSkipElements = true;
                            }

                            if (GUILayout.Button("Add Selection"))
                            {
                                HEU_SelectionWindow.ShowWindow(inputNode.HandleSelectedObjectsForInputHDAs, typeof(HEU_HoudiniAssetRoot));
                            }

                            if (GUILayout.Button("Clear"))
                            {
                                inputAssetsProperty.ClearArray();
                                bSkipElements = true;
                            }
                        }

                        if (!bSkipElements)
                        {
                            using (var vs1 = new EditorGUILayout.VerticalScope())
                            {
                                for (int i = 0; i < inputCount; ++i)
                                {
                                    using (var hs2 = new EditorGUILayout.HorizontalScope())
                                    {
                                        EditorGUILayout.LabelField("Input " + (i + 1));

                                        if (GUILayout.Button("+", GUILayout.Width(plusButtonWidth)))
                                        {
                                            inputAssetsProperty.InsertArrayElementAtIndex(i);
                                            break;
                                        }

                                        if (GUILayout.Button("-", GUILayout.Width(plusButtonWidth)))
                                        {
                                            inputAssetsProperty.DeleteArrayElementAtIndex(i);
                                            break;
                                        }
                                    }

                                    EditorGUI.indentLevel++;
                                    using (var vs4 = new EditorGUILayout.VerticalScope())
                                    {
                                        HEU_InputNodeUICache.HEU_InputAssetUICache assetCache = inputNode._uiCache._inputAssetCache[i];

                                        UnityEngine.Object setObject = EditorGUILayout.ObjectField(assetCache._gameObjectProperty.objectReferenceValue, typeof(HEU_HoudiniAssetRoot), true);
                                        if (setObject != assetCache._gameObjectProperty.objectReferenceValue)
                                        {
                                            GameObject inputGO = setObject != null ? (setObject as HEU_HoudiniAssetRoot).gameObject : null;
                                            // Check not setting same asset as self
                                            if (inputGO == null || inputGO != inputNode.ParentAsset.RootGameObject)
                                            {
                                                assetCache._gameObjectProperty.objectReferenceValue = inputGO;
                                            }
                                        }
                                    }
                                    EditorGUI.indentLevel--;
                                }
                            }
                        }
                    }
                }
                //else if (inputObjectType == HEU_InputNode.InputObjectType.CURVE)
                //{
                //	TODO INPUT CURVE
                //}
                else if (inputObjectType == HEU_InputNode.InputObjectType.UNITY_MESH)
                {
                    SerializedProperty inputObjectsProperty = inputNode._uiCache._inputObjectsProperty;
                    if (inputObjectsProperty != null)
                    {
                        bool bSkipElements = false;

                        HEU_EditorUI.DrawSeparator();

                        EditorGUILayout.LabelField(string.Format("{0} input objects", inputObjectsProperty.arraySize));

                        using (var hs1 = new EditorGUILayout.HorizontalScope())
                        {
                            if (GUILayout.Button("Add Slot"))
                            {
                                inputObjectsProperty.arraySize++;
                                FixUpScaleProperty(inputObjectsProperty, inputObjectsProperty.arraySize - 1);

                                bSkipElements = true;
                            }

                            if (GUILayout.Button("Add Selection"))
                            {
                                HEU_SelectionWindow.ShowWindow(inputNode.HandleSelectedObjectsForInputObjects, typeof(GameObject));
                            }

                            if (GUILayout.Button("Clear"))
                            {
                                inputObjectsProperty.ClearArray();
                                bSkipElements = true;
                            }
                        }

                        if (!bSkipElements)
                        {
                            using (var vs1 = new EditorGUILayout.VerticalScope())
                            {
                                int inputCount = inputObjectsProperty.arraySize;
                                for (int i = 0; i < inputCount; ++i)
                                {
                                    using (var hs2 = new EditorGUILayout.HorizontalScope())
                                    {
                                        EditorGUILayout.LabelField("Input " + (i + 1));

                                        //using (var vs3 = new EditorGUILayout.VerticalScope())
                                        {
                                            if (GUILayout.Button("+", GUILayout.Width(plusButtonWidth)))
                                            {
                                                inputObjectsProperty.InsertArrayElementAtIndex(i);
                                                FixUpScaleProperty(inputObjectsProperty, i);
                                                break;
                                            }

                                            if (GUILayout.Button("-", GUILayout.Width(plusButtonWidth)))
                                            {
                                                inputObjectsProperty.DeleteArrayElementAtIndex(i);
                                                break;
                                            }
                                        }
                                    }

                                    EditorGUI.indentLevel++;
                                    using (var vs4 = new EditorGUILayout.VerticalScope())
                                    {
                                        HEU_InputNodeUICache.HEU_InputObjectUICache objectCache = inputNode._uiCache._inputObjectCache[i];

                                        EditorGUILayout.PropertyField(objectCache._gameObjectProperty, GUIContent.none);

                                        using (new EditorGUI.DisabledScope(!inputNode._uiCache._keepWorldTransformProperty.boolValue))
                                        {
                                            objectCache._transformOffsetProperty.boolValue = HEU_EditorUI.DrawToggleLeft(objectCache._transformOffsetProperty.boolValue, "Transform Offset");
                                            if (objectCache._transformOffsetProperty.boolValue)
                                            {
                                                objectCache._translateProperty.vector3Value = EditorGUILayout.Vector3Field(translateLabel, objectCache._translateProperty.vector3Value);
                                                objectCache._rotateProperty.vector3Value    = EditorGUILayout.Vector3Field(rotateLabel, objectCache._rotateProperty.vector3Value);
                                                objectCache._scaleProperty.vector3Value     = EditorGUILayout.Vector3Field(scaleLabel, objectCache._scaleProperty.vector3Value);
                                            }
                                        }
                                    }
                                    EditorGUI.indentLevel--;
                                }
                            }
                        }
                    }
                }
            }

            EditorGUI.indentLevel--;

            EditorGUILayout.EndVertical();

            if (EditorGUI.EndChangeCheck())
            {
                inputNode._uiCache._inputNodeSerializedObject.ApplyModifiedProperties();

                // When cooking, this will force input data to be uploaded
                inputNode.RequiresUpload = true;
            }
        }