Exemplo n.º 1
0
 protected void DelayCreateCall()
 {
     AkWwiseComponentPicker.Create(AkWwiseProjectData.WwiseObjectType.EVENT, m_guidProperty, m_IDProperty,
                                   akEvent.serializedObject, m_pickerPos);
 }
Exemplo n.º 2
0
    public static void Create(AkWwiseProjectData.WwiseObjectType in_type, UnityEditor.SerializedProperty[] in_guid,
                              UnityEditor.SerializedProperty[] in_ID, UnityEditor.SerializedObject in_serializedObject, UnityEngine.Rect in_pos)
    {
        if (s_componentPicker == null)
        {
            s_componentPicker = CreateInstance <AkWwiseComponentPicker>();

            //position the window below the button
            var pos = new UnityEngine.Rect(in_pos.x, in_pos.yMax, 0, 0);

            //If the window gets out of the screen, we place it on top of the button instead
            if (in_pos.yMax > UnityEngine.Screen.currentResolution.height / 2)
            {
                pos.y = in_pos.y - UnityEngine.Screen.currentResolution.height / 2;
            }

            //We show a drop down window which is automatically destroyed when focus is lost
            s_componentPicker.ShowAsDropDown(pos,
                                             new UnityEngine.Vector2(in_pos.width >= 250 ? in_pos.width : 250, UnityEngine.Screen.currentResolution.height / 2));

            s_componentPicker.m_selectedItemGuid = in_guid;
            s_componentPicker.m_selectedItemID   = in_ID;
            s_componentPicker.m_serializedObject = in_serializedObject;
            s_componentPicker.m_type             = in_type;

            //Make a backup of the tree's expansion status and replace it with an empty list to make sure nothing will get expanded
            //when we populate the tree
            var expandedItemsBackUp = AkWwiseProjectInfo.GetData().ExpandedItems;
            AkWwiseProjectInfo.GetData().ExpandedItems = new System.Collections.Generic.List <string>();

            s_componentPicker.m_treeView.AssignDefaults();
            s_componentPicker.m_treeView.SetRootItem(
                System.IO.Path.GetFileNameWithoutExtension(WwiseSetupWizard.Settings.WwiseProjectPath),
                AkWwiseProjectData.WwiseObjectType.PROJECT);

            //Populate the tree with the correct type
            if (in_type == AkWwiseProjectData.WwiseObjectType.EVENT)
            {
                s_componentPicker.m_treeView.PopulateItem(s_componentPicker.m_treeView.RootItem, "Events",
                                                          AkWwiseProjectInfo.GetData().EventWwu);
            }
            else if (in_type == AkWwiseProjectData.WwiseObjectType.SWITCH)
            {
                s_componentPicker.m_treeView.PopulateItem(s_componentPicker.m_treeView.RootItem, "Switches",
                                                          AkWwiseProjectInfo.GetData().SwitchWwu);
            }
            else if (in_type == AkWwiseProjectData.WwiseObjectType.STATE)
            {
                s_componentPicker.m_treeView.PopulateItem(s_componentPicker.m_treeView.RootItem, "States",
                                                          AkWwiseProjectInfo.GetData().StateWwu);
            }
            else if (in_type == AkWwiseProjectData.WwiseObjectType.SOUNDBANK)
            {
                s_componentPicker.m_treeView.PopulateItem(s_componentPicker.m_treeView.RootItem, "Banks",
                                                          AkWwiseProjectInfo.GetData().BankWwu);
            }
            else if (in_type == AkWwiseProjectData.WwiseObjectType.AUXBUS)
            {
                s_componentPicker.m_treeView.PopulateItem(s_componentPicker.m_treeView.RootItem, "Auxiliary Busses",
                                                          AkWwiseProjectInfo.GetData().AuxBusWwu);
            }
            else if (in_type == AkWwiseProjectData.WwiseObjectType.GAMEPARAMETER)
            {
                s_componentPicker.m_treeView.PopulateItem(s_componentPicker.m_treeView.RootItem, "Game Parameters",
                                                          AkWwiseProjectInfo.GetData().RtpcWwu);
            }
            else if (in_type == AkWwiseProjectData.WwiseObjectType.TRIGGER)
            {
                s_componentPicker.m_treeView.PopulateItem(s_componentPicker.m_treeView.RootItem, "Triggers",
                                                          AkWwiseProjectInfo.GetData().TriggerWwu);
            }
            else if (in_type == AkWwiseProjectData.WwiseObjectType.ACOUSTICTEXTURE)
            {
                s_componentPicker.m_treeView.PopulateItem(s_componentPicker.m_treeView.RootItem, "Virtual Acoustics",
                                                          AkWwiseProjectInfo.GetData().AcousticTextureWwu);
            }

            AK.Wwise.TreeView.TreeViewItem item = null;

            var byteArray = AkUtilities.GetByteArrayProperty(in_guid[0]);
            if (byteArray != null)
            {
                item = s_componentPicker.m_treeView.GetItemByGuid(new System.Guid(byteArray));
            }

            if (item != null)
            {
                item.ParentControl.SelectedItem = item;

                var itemIndexFromRoot = 0;

                //Expand all the parents of the selected item.
                //Count the number of items that are displayed before the selected item
                while (true)
                {
                    item.IsExpanded = true;

                    if (item.Parent != null)
                    {
                        itemIndexFromRoot += item.Parent.Items.IndexOf(item) + 1;
                        item = item.Parent;
                    }
                    else
                    {
                        break;
                    }
                }

                //Scroll down the window to make sure that the selected item is always visible when the window opens
                var itemHeight = item.ParentControl.m_skinSelected.button.CalcSize(new UnityEngine.GUIContent(item.Header)).y +
                                 2.0f;                 //there seems to be 1 pixel between each item so we add 2 pixels(top and bottom)
                s_componentPicker.m_treeView.SetScrollViewPosition(new UnityEngine.Vector2(0.0f,
                                                                                           itemHeight * itemIndexFromRoot - UnityEngine.Screen.currentResolution.height / 4));
            }

            //Restore the tree's expansion status
            AkWwiseProjectInfo.GetData().ExpandedItems = expandedItemsBackUp;
        }
    }
Exemplo n.º 3
0
 private void DelayCreateCall()
 {
     AkWwiseComponentPicker.Create(m_objectType, m_guidProperty, m_IDProperty, m_serializedObject, m_pickerPos);
 }
Exemplo n.º 4
0
 private void DelayCreateCall()
 {
     AkWwiseComponentPicker.Create(s_objectType, s_guidProperty, s_serializedObject, s_pickerPos);
 }
Exemplo n.º 5
0
        public override void OnGUI(UnityEngine.Rect position, UnityEditor.SerializedProperty property, UnityEngine.GUIContent label)
        {
            // Get unique control Id
            int controlId = UnityEngine.GUIUtility.GetControlID(label, UnityEngine.FocusType.Passive);

            UnityEditor.EditorGUI.BeginProperty(position, label, property);

            var wwiseObjectReference = property.FindPropertyRelative("WwiseObjectReference");

            HandleDragAndDrop(wwiseObjectReference, position);

            position = UnityEditor.EditorGUI.PrefixLabel(position, controlId, label);

            var style = new UnityEngine.GUIStyle(UnityEngine.GUI.skin.button);

            style.alignment = UnityEngine.TextAnchor.MiddleLeft;
            style.fontStyle = UnityEngine.FontStyle.Normal;

            var componentName = GetComponentName(wwiseObjectReference);

            if (string.IsNullOrEmpty(componentName))
            {
                componentName          = "No " + WwiseObjectType + " is currently selected";
                style.normal.textColor = UnityEngine.Color.red;
            }

            if (UnityEngine.GUI.Button(position, componentName, style))
            {
                new AkWwiseComponentPicker.PickerCreator
                {
                    objectType           = WwiseObjectType,
                    wwiseObjectReference = wwiseObjectReference,
                    serializedObject     = property.serializedObject,
                    //Current selected object
                    currentWwiseObjectReference = GetWwiseObjectReference(wwiseObjectReference),
                    //We're currently clicking focus windows must be the right
                    pickedSourceEditorWindow = UnityEditor.EditorWindow.focusedWindow,
                    //Useful to control event source
                    pickedSourceControlId = controlId,
                    pickerPosition        = AkUtilities.GetLastRectAbsolute(position),
                };
            }

            // Check picker window close event and we're in the right drawer instance using control ID
            if (UnityEngine.Event.current.commandName == AkWwiseComponentPicker.PickerClosedEventName &&
                controlId == AkWwiseComponentPicker.GetObjectPickerControlID())
            {
                var oldValue = GetWwiseObjectReference(wwiseObjectReference);
                var newValue = AkWwiseComponentPicker.GetObjectPickerObjectReference();

                if (oldValue != newValue)
                {
                    // Serialized object updating
                    wwiseObjectReference.serializedObject.Update();
                    SetSerializedObject(wwiseObjectReference, newValue);
                    wwiseObjectReference.serializedObject.ApplyModifiedProperties();

                    // Force GUI modification, to send back to the base component drawer
                    UnityEngine.GUI.changed = true;
                }
            }

            UnityEditor.EditorGUI.EndProperty();
        }
    public static void Create(AkWwiseProjectData.WwiseObjectType in_type, SerializedProperty[] in_guid, SerializedObject in_serializedObject, Rect in_pos)
    {
        if(s_componentPicker == null)
        {
            s_componentPicker = ScriptableObject.CreateInstance<AkWwiseComponentPicker> ();

            //position the window below the button
            Rect pos = new Rect (in_pos.x, in_pos.yMax, 0, 0);

            //If the window gets out of the screen, we place it on top of the button instead
            if(in_pos.yMax > (Screen.currentResolution.height / 2))
            {
                pos.y = in_pos.y - (Screen.currentResolution.height / 2);
            }

            //We show a drop down window which is automatically destoyed when focus is lost
            s_componentPicker.ShowAsDropDown(pos, new Vector2 (in_pos.width >= 250 ? in_pos.width : 250, Screen.currentResolution.height / 2));

            s_componentPicker.m_selectedItemGuid	= in_guid;
            s_componentPicker.m_serializedObject	= in_serializedObject;
            s_componentPicker.m_type 				= in_type;

            //Make a backup of the tree's expansion status and replace it with an empty list to make sure nothing will get expanded
            //when we populate the tree
            List<string> expandedItemsBackUp = AkWwiseProjectInfo.GetData ().ExpandedItems;
            AkWwiseProjectInfo.GetData ().ExpandedItems = new List<string> ();

            s_componentPicker.m_treeView.AssignDefaults();
            s_componentPicker.m_treeView.SetRootItem(System.IO.Path.GetFileNameWithoutExtension(WwiseSetupWizard.Settings.WwiseProjectPath), AkWwiseProjectData.WwiseObjectType.PROJECT);

            //Populate the tree with the correct type
            if(in_type == AkWwiseProjectData.WwiseObjectType.EVENT)
            {
                s_componentPicker.m_treeView.PopulateItem(s_componentPicker.m_treeView.RootItem, "Events", AkWwiseProjectInfo.GetData().EventWwu);
            }
            else if(in_type == AkWwiseProjectData.WwiseObjectType.SWITCH)
            {
                s_componentPicker.m_treeView.PopulateItem(s_componentPicker.m_treeView.RootItem, "Switches", AkWwiseProjectInfo.GetData().SwitchWwu);
            }
            else if(in_type == AkWwiseProjectData.WwiseObjectType.STATE)
            {
                s_componentPicker.m_treeView.PopulateItem(s_componentPicker.m_treeView.RootItem, "States", AkWwiseProjectInfo.GetData().StateWwu);
            }
            else if(in_type == AkWwiseProjectData.WwiseObjectType.SOUNDBANK)
            {
                s_componentPicker.m_treeView.PopulateItem(s_componentPicker.m_treeView.RootItem, "Banks", AkWwiseProjectInfo.GetData().BankWwu);
            }
            else if(in_type == AkWwiseProjectData.WwiseObjectType.AUXBUS)
            {
                s_componentPicker.m_treeView.PopulateItem(s_componentPicker.m_treeView.RootItem, "Auxiliary Busses", AkWwiseProjectInfo.GetData().AuxBusWwu);
            }

            TreeViewItem item = s_componentPicker.m_treeView.GetItemByGuid(new Guid(AkUtilities.GetByteArrayProperty( in_guid[0])));
            if(item != null)
            {
                item.ParentControl.SelectedItem = item;

                int itemIndexFromRoot = 0;

                //Expand all the parents of the selected item.
                //Count the number of items that are displayed before the selected item
                while(true)
                {
                    item.IsExpanded = true;

                    if(item.Parent != null)
                    {
                        itemIndexFromRoot += item.Parent.Items.IndexOf(item) + 1;
                        item = item.Parent;
                    }
                    else
                    {
                        break;
                    }
                }

                //Scroll down the window to make sure that the selected item is always visible when the window opens
                float itemHeight =	item.ParentControl.m_skinSelected.button.CalcSize(new GUIContent(item.Header)).y + 2.0f; //there seems to be 1 pixel between each item so we add 2 pixels(top and bottom)
                s_componentPicker.m_treeView.SetScrollViewPosition(new Vector2(0.0f, (itemHeight*itemIndexFromRoot)-(Screen.currentResolution.height / 4)));
            }

            //Restore the tree's expansion status
            AkWwiseProjectInfo.GetData ().ExpandedItems = expandedItemsBackUp;
        }
    }