Example #1
0
        static public int CreateLayer(string name)
        {
            //  https://forum.unity.com/threads/adding-layer-by-script.41970/#post-2274824
            UnityEditor.SerializedObject   tagManager = new UnityEditor.SerializedObject(UnityEditor.AssetDatabase.LoadAllAssetsAtPath("ProjectSettings/TagManager.asset")[0]);
            UnityEditor.SerializedProperty layers     = tagManager.FindProperty("layers");
            bool ExistLayer = false;

            for (int i = 8; i < layers.arraySize; i++)
            {
                UnityEditor.SerializedProperty layerSP = layers.GetArrayElementAtIndex(i);

                if (layerSP.stringValue == name)
                {
                    ExistLayer = true;
                    return(i);
                }
            }
            for (int j = 8; j < layers.arraySize; j++)
            {
                UnityEditor.SerializedProperty layerSP = layers.GetArrayElementAtIndex(j);
                if (layerSP.stringValue == "" && !ExistLayer)
                {
                    layerSP.stringValue = name;
                    tagManager.ApplyModifiedProperties();

                    return(j);
                }
            }

            return(0);
        }
    private System.Collections.Generic.List <uint> GetCurrentTriggers()
    {
        var newList = new System.Collections.Generic.List <uint>();

        for (var i = 0; i < m_triggerList.arraySize; i++)
        {
            newList.Add((uint)m_triggerList.GetArrayElementAtIndex(i).intValue);
        }

        return(newList);
    }
Example #3
0
        static void WriteEntry(UnityEditor.SerializedProperty spAxes, InputManagerEntry entry)
        {
            if (InputAlreadyRegistered(entry.name, entry.kind, spAxes))
            {
                return;
            }

            spAxes.InsertArrayElementAtIndex(spAxes.arraySize);
            var spAxis = spAxes.GetArrayElementAtIndex(spAxes.arraySize - 1);

            spAxis.FindPropertyRelative("m_Name").stringValue            = entry.name;
            spAxis.FindPropertyRelative("descriptiveName").stringValue   = entry.desc;
            spAxis.FindPropertyRelative("negativeButton").stringValue    = entry.btnNegative;
            spAxis.FindPropertyRelative("altNegativeButton").stringValue = entry.altBtnNegative;
            spAxis.FindPropertyRelative("positiveButton").stringValue    = entry.btnPositive;
            spAxis.FindPropertyRelative("altPositiveButton").stringValue = entry.altBtnPositive;
            spAxis.FindPropertyRelative("gravity").floatValue            = entry.gravity;
            spAxis.FindPropertyRelative("dead").floatValue        = entry.deadZone;
            spAxis.FindPropertyRelative("sensitivity").floatValue = entry.sensitivity;
            spAxis.FindPropertyRelative("snap").boolValue         = entry.snap;
            spAxis.FindPropertyRelative("invert").boolValue       = entry.invert;
            spAxis.FindPropertyRelative("type").intValue          = (int)entry.kind;
            spAxis.FindPropertyRelative("axis").intValue          = (int)entry.axis;
            spAxis.FindPropertyRelative("joyNum").intValue        = (int)entry.joystick;
        }
Example #4
0
    public override void OnInspectorGUI()
    {
        serializedObject.Update();

        using (new UnityEditor.EditorGUILayout.VerticalScope("box"))
        {
            UnityEditor.EditorGUILayout.PropertyField(initialState);
            m_OpenPortalEventHandlerInspector.OnGUI();
            m_ClosePortalEventHandlerInspector.OnGUI();
        }

        m_roomPortal.UpdateRooms();

        var labels   = new[] { "Back Room", "Front Room" };
        var tooltips = new[] { "The highest priority, active and enabled AkRoom component overlapping the back surface of this AkRoomPortal.",
                               "The highest priority, active and enabled AkRoom component overlapping the front surface of this AkRoomPortal." };

        var wasEnabled = UnityEngine.GUI.enabled;

        UnityEngine.GUI.enabled = false;

        for (var i = 0; i < AkRoomPortal.MAX_ROOMS_PER_PORTAL; i++)
        {
            UnityEditor.EditorGUILayout.PropertyField(rooms.GetArrayElementAtIndex(i), new UnityEngine.GUIContent(labels[i], tooltips[i]), true);
        }

        UnityEngine.GUI.enabled = wasEnabled;

        RoomCheck(m_roomPortal);

        serializedObject.ApplyModifiedProperties();
    }
Example #5
0
        public override void OnInspectorGUI()
        {
            base.OnInspectorGUI();

            if (m_ShadowRegistry == null)
            {
                return;
            }

            AdditionalShadowData asd = (AdditionalShadowData)target;

            if (asd == null)
            {
                return;
            }

            UnityEditor.EditorGUI.BeginChangeCheck();

            m_ShadowRegistry.Draw(asd.gameObject.GetComponent <Light>());
            serializedObject.Update();

            m_ShadowmapRenderFlags.enumValueIndex = (int)(ShadowmapRenderFlags)UnityEditor.EditorGUILayout.EnumFlagsField("Render Flags", (ShadowmapRenderFlags)m_ShadowmapRenderFlags.enumValueIndex);

            // cascade code
            if (asd.gameObject.GetComponent <Light>().type == LightType.Directional)
            {
                UnityEditor.EditorGUI.BeginChangeCheck();
                UnityEditor.EditorGUILayout.PropertyField(m_ShadowCascadeCount);
                if (UnityEditor.EditorGUI.EndChangeCheck())
                {
                    const int kMaxCascades = (int)ShadowAtlas.k_MaxCascadesInShader;  // depending on where you look this is either 32 or 4, so we're limiting it to 4 for now
                    int       newcnt       = m_ShadowCascadeCount.intValue <= 0 ? 1 : (m_ShadowCascadeCount.intValue > kMaxCascades ? kMaxCascades : m_ShadowCascadeCount.intValue);
                    m_ShadowCascadeCount.intValue    = newcnt;
                    m_ShadowCascadeRatios.arraySize  = newcnt - 1;
                    m_ShadowCascadeBorders.arraySize = newcnt;
                }
                UnityEditor.EditorGUI.indentLevel++;
                for (int i = 0; i < m_ShadowCascadeRatios.arraySize; i++)
                {
                    UnityEditor.EditorGUILayout.Slider(m_ShadowCascadeRatios.GetArrayElementAtIndex(i), 0.0f, 1.0f, new GUIContent("Cascade " + i));
                }
                for (int i = 0; i < m_ShadowCascadeBorders.arraySize; i++)
                {
                    UnityEditor.EditorGUILayout.Slider(m_ShadowCascadeBorders.GetArrayElementAtIndex(i), 0.0f, 1.0f, new GUIContent("Transition " + i));
                }
                UnityEditor.EditorGUI.indentLevel--;
            }

            if (UnityEditor.EditorGUI.EndChangeCheck())
            {
                UnityEditor.EditorUtility.SetDirty(asd);
                UnityEditor.SceneManagement.EditorSceneManager.MarkAllScenesDirty();
                UnityEditor.SceneView.RepaintAll();
            }
            serializedObject.ApplyModifiedProperties();
        }
Example #6
0
        static void CreateLayer()
        {
#if UNITY_EDITOR
            /* when running in the editor, check that UI_layer and UI_layer + 1 are free,
             * and then give them useful names.  This is based on
             * https://forum.unity3d.com/threads/adding-layer-by-script.41970/reply?quote=2274824
             * but with a constant value for UI_layer.  The problem is that this code cannot run
             * outside the editor.  So I can find no reasonable way to dynamically pick an unused
             * layer in builds that run outside the editor...
             */
            UnityEditor.SerializedObject tagManager = new UnityEditor.SerializedObject(
                UnityEditor.AssetDatabase.LoadAllAssetsAtPath("ProjectSettings/TagManager.asset")[0]);
            UnityEditor.SerializedProperty layers  = tagManager.FindProperty("layers");
            UnityEditor.SerializedProperty layer29 = layers.GetArrayElementAtIndex(UI_layer);
            UnityEditor.SerializedProperty layer30 = layers.GetArrayElementAtIndex(UI_layer + 1);

            if (layer29.stringValue == "")
            {
                layer29.stringValue = "BaroqueUI dialog";
                tagManager.ApplyModifiedProperties();
            }
            if (layer30.stringValue == "")
            {
                layer30.stringValue = "BaroqueUI dialog rendering";
                tagManager.ApplyModifiedProperties();
            }

            Debug.Assert(layer29.stringValue == "BaroqueUI dialog");
            Debug.Assert(layer30.stringValue == "BaroqueUI dialog rendering");
#endif

            /* we want all cameras to hide these two layers */
            if (!camera_onprecull_set)
            {
                Camera.onPreCull    += Camera_OnPreCull;
                camera_onprecull_set = true;
            }
        }
Example #7
0
 override public void OnInspectorGUIBasic(UCL_TC_Data iTcData, UnityEditor.SerializedProperty iSerializedProperty, Transform iTransform)
 {
     base.OnInspectorGUIBasic(iTcData, iSerializedProperty, iTransform);
     UnityEditor.SerializedProperty aTransformDatas = iSerializedProperty.FindPropertyRelative("m_Transform");
     if (iTransform != null && aTransformDatas != null)
     {
         if (aTransformDatas.arraySize == 0)
         {//Init
             aTransformDatas.InsertArrayElementAtIndex(0);
             aTransformDatas.InsertArrayElementAtIndex(1);
             aTransformDatas.GetArrayElementAtIndex(0).objectReferenceValue = iTransform;
         }
     }
 }
Example #8
0
        private static void AddTag(string _tag)
        {
#if UNITY_EDITOR
            UnityEngine.Object[] _asset = UnityEditor.AssetDatabase.LoadAllAssetsAtPath("ProjectSettings/TagManager.asset");
            if ((_asset != null) && (_asset.Length > 0))
            {
                UnityEditor.SerializedObject   _object = new UnityEditor.SerializedObject(_asset[0]);
                UnityEditor.SerializedProperty _tags   = _object.FindProperty("tags");

                for (int i = 0; i < _tags.arraySize; ++i)
                {
                    if (_tags.GetArrayElementAtIndex(i).stringValue == _tag)
                    {
                        return;
                    }
                }

                _tags.InsertArrayElementAtIndex(0);
                _tags.GetArrayElementAtIndex(0).stringValue = _tag;
                _object.ApplyModifiedProperties();
                _object.Update();
            }
#endif
        }
Example #9
0
        static bool InputAlreadyRegistered(string name, InputManagerEntry.Kind kind, UnityEditor.SerializedProperty spAxes)
        {
            for (var i = 0; i < spAxes.arraySize; ++i)
            {
                var spAxis    = spAxes.GetArrayElementAtIndex(i);
                var axisName  = spAxis.FindPropertyRelative("m_Name").stringValue;
                var kindValue = spAxis.FindPropertyRelative("type").intValue;
                if (axisName == name && (int)kind == kindValue)
                {
                    return(true);
                }
            }

            return(false);
        }
        public override void OnInspectorGUI()
        {
            base.OnInspectorGUI();

            AdditionalShadowData asd = (AdditionalShadowData)target;

            if (asd == null)
            {
                return;
            }

            UnityEditor.EditorGUI.BeginChangeCheck();

            serializedObject.Update();

            // cascade code
            if (asd.gameObject.GetComponent <Light>().type == LightType.Directional)
            {
                UnityEditor.EditorGUI.BeginChangeCheck();
                UnityEditor.EditorGUILayout.PropertyField(m_ShadowCascadeCount);
                if (UnityEditor.EditorGUI.EndChangeCheck())
                {
                    const int kMaxCascades = 4;
                    int       newcnt       = m_ShadowCascadeCount.intValue <= 0 ? 1 : (m_ShadowCascadeCount.intValue > kMaxCascades ? kMaxCascades : m_ShadowCascadeCount.intValue);
                    m_ShadowCascadeCount.intValue    = newcnt;
                    m_ShadowCascadeRatios.arraySize  = newcnt - 1;
                    m_ShadowCascadeBorders.arraySize = newcnt;
                }
                UnityEditor.EditorGUI.indentLevel++;
                for (int i = 0; i < m_ShadowCascadeRatios.arraySize; i++)
                {
                    UnityEditor.EditorGUILayout.Slider(m_ShadowCascadeRatios.GetArrayElementAtIndex(i), 0.0f, 1.0f, new GUIContent("Cascade " + i));
                }
                for (int i = 0; i < m_ShadowCascadeBorders.arraySize; i++)
                {
                    UnityEditor.EditorGUILayout.Slider(m_ShadowCascadeBorders.GetArrayElementAtIndex(i), 0.0f, 1.0f, new GUIContent("Transition " + i));
                }
                UnityEditor.EditorGUI.indentLevel--;
            }

            if (UnityEditor.EditorGUI.EndChangeCheck())
            {
                UnityEditor.EditorUtility.SetDirty(asd);
                UnityEditor.SceneManagement.EditorSceneManager.MarkAllScenesDirty();
                UnityEditor.SceneView.RepaintAll();
            }
            serializedObject.ApplyModifiedProperties();
        }
Example #11
0
    public static byte[] GetByteArrayProperty(UnityEditor.SerializedProperty property)
    {
        if (!property.isArray || property.arraySize == 0)
        {
            return(null);
        }

        var byteArray = new byte[property.arraySize];

        for (var i = 0; i < byteArray.Length; i++)
        {
            byteArray[i] = (byte)property.GetArrayElementAtIndex(i).intValue;
        }

        return(byteArray);
    }
        private static bool IsLightweightRenderPipelineSetupCorrectly()
        {
            if (s_pipelineSetupOk)
            {
                return(true);
            }
            // check if the current Forward Renderer has the ProjectorRendererFeature instance.
            UniversalRenderPipelineAsset renderPipelineAsset = UniversalRenderPipeline.asset;

            if (renderPipelineAsset == null)
            {
                return(false);
            }
            UnityEditor.SerializedObject   serializedObject             = new UnityEditor.SerializedObject(renderPipelineAsset);
            UnityEditor.SerializedProperty rendererDataListProperty     = serializedObject.FindProperty("m_RendererDataList");
            UnityEditor.SerializedProperty defaultRendererIndexProperty = serializedObject.FindProperty("m_DefaultRendererIndex");
            ScriptableRendererData         rendererData = null;

            if (defaultRendererIndexProperty.intValue < rendererDataListProperty.arraySize)
            {
                rendererData = rendererDataListProperty.GetArrayElementAtIndex(defaultRendererIndexProperty.intValue).objectReferenceValue as ScriptableRendererData;
            }
            if (rendererData == null)
            {
                Debug.LogError("No default renderer found in the current Universal Render Pipeline Asset.", renderPipelineAsset);
            }
            else
            {
                bool found = false;
                foreach (var rendererFeature in rendererData.rendererFeatures)
                {
                    if (rendererFeature is ProjectorRendererFeature)
                    {
                        found = true;
                        break;
                    }
                }
                if (!found)
                {
                    Debug.LogError("ProjectorRendererFeature is not added to the current Forward Renderer Data.", rendererData);
                    return(false);
                }
            }
            s_pipelineSetupOk = true;
            return(true);
        }
Example #13
0
        private static byte[] GetByteArray(UnityEditor.SerializedProperty property)
        {
            if (property == null || !property.isArray)
            {
                return(null);
            }

            if (property.arraySize != 16)
            {
                return(null);
            }

            var byteArray = new byte[16];

            for (var i = 0; i < 16; ++i)
            {
                byteArray[i] = (byte)property.GetArrayElementAtIndex(i).intValue;
            }

            return(byteArray);
        }
Example #14
0
    private void OnEnable()
    {
        m_envPortal    = target as AkEnvironmentPortal;
        m_environments = serializedObject.FindProperty("environments");
        m_axis         = serializedObject.FindProperty("axis");
        m_envList      = serializedObject.FindProperty("envList");

        FindOverlappingEnvironments();
        for (var i = 0; i < AkEnvironmentPortal.MAX_ENVIRONMENTS_PER_PORTAL; i++)
        {
            m_selectedIndex[i] = 0;

            var list = m_envList.GetArrayElementAtIndex(i).FindPropertyRelative("list");
            for (var j = 0; j < list.arraySize; ++j)
            {
                if (list.GetArrayElementAtIndex(j).objectReferenceValue == m_environments.GetArrayElementAtIndex(i).objectReferenceValue)
                {
                    m_selectedIndex[i] = j;
                    break;
                }
            }
        }
    }
Example #15
0
        private static void AddLayer(string _name)
        {
#if UNITY_EDITOR
            if (LayerMask.NameToLayer(_name) != -1)
            {
                return;
            }

            UnityEditor.SerializedObject _tag_manager = new UnityEditor.SerializedObject(UnityEditor.AssetDatabase.LoadAllAssetsAtPath("ProjectSettings/TagManager.asset")[0]);

            UnityEditor.SerializedProperty _layers = _tag_manager.FindProperty("layers");
            if (_layers == null || !_layers.isArray)
            {
                Debug.LogWarning("Sorry, can't set up the layers! It's possible the format of the layers and tags data has changed in this version of Unity. Please add the required layer '" + _name + "' by hand!");
                return;
            }

            int _layer_index = -1;
            for (int _i = 8; _i < 32; _i++)
            {
                _layer_index = _i;
                UnityEditor.SerializedProperty _layer = _layers.GetArrayElementAtIndex(_i);

                //Debug.Log( _layer_index + " - " + _layer.stringValue );

                if (_layer.stringValue == "")
                {
                    Debug.Log("Setting up layers.  Layer " + _layer_index + " is now called " + _name);
                    _layer.stringValue = _name;
                    break;
                }
            }

            _tag_manager.ApplyModifiedProperties();
#endif
        }
Example #16
0
        public static bool SearchAndProcessWwiseTypes(UnityEditor.SerializedProperty property, UnityEditor.SerializedProperty endProperty = null)
        {
            var returnValue = false;

            if (property == null)
            {
                return(returnValue);
            }

            var recurse = false;

            if (property.isArray)
            {
                if (property.arraySize > 0)
                {
                    var copyProperty = property.Copy();
                    copyProperty.Next(false);
                    returnValue = SearchAndProcessWwiseTypes(property.GetArrayElementAtIndex(0), copyProperty);
                }
            }
            else if (property.propertyType == UnityEditor.SerializedPropertyType.Generic)
            {
                recurse = true;

                var wwiseObjectType = GetWwiseObjectType(property);
                if (wwiseObjectType != WwiseObjectType.None)
                {
                    // At this point, we know that the property's type's name is the same as one of our WwiseTypes.
                    var valueGuidProperty            = property.FindPropertyRelative("valueGuidInternal");
                    var wwiseObjectReferenceProperty = property.FindPropertyRelative("WwiseObjectReference");
                    if (valueGuidProperty != null && wwiseObjectReferenceProperty != null)
                    {
                        // At this point, we can be **pretty** sure that we are dealing with a WwiseType.
                        // The uncertainty lies with the fact that the property.type is the non-qualified name of the property's type.
                        recurse = false;

                        var idProperty = property.FindPropertyRelative("idInternal");
                        if (wwiseObjectType == WwiseObjectType.State || wwiseObjectType == WwiseObjectType.Switch)
                        {
                            var groupGuidProperty = property.FindPropertyRelative("groupGuidInternal");
                            if (groupGuidProperty != null)
                            {
                                var groupIdProperty = property.FindPropertyRelative("groupIdInternal");
                                returnValue = ProcessDoubleGuidType(wwiseObjectReferenceProperty, wwiseObjectType, valueGuidProperty, idProperty, groupGuidProperty, groupIdProperty);
                            }
                        }
                        else
                        {
                            returnValue = ProcessSingleGuidType(wwiseObjectReferenceProperty, wwiseObjectType, valueGuidProperty, idProperty);
                        }
                    }
                }
            }

            if (endProperty != null && UnityEditor.SerializedProperty.EqualContents(property, endProperty))
            {
                return(returnValue);
            }

            if (!property.Next(recurse))
            {
                return(returnValue);
            }

            // property is modified above, so this check needs to be performed again.
            if (endProperty != null && UnityEditor.SerializedProperty.EqualContents(property, endProperty))
            {
                return(returnValue);
            }

            return(SearchAndProcessWwiseTypes(property, endProperty) || returnValue);
        }
Example #17
0
    public override void OnChildInspectorGUI()
    {
        //Save trigger mask to know when it changes
        triggerList = m_AkAmbient.triggerList;

        base.OnChildInspectorGUI();

        if (UnityEngine.Event.current.type == UnityEngine.EventType.ExecuteCommand &&
            UnityEngine.Event.current.commandName == "ObjectSelectorClosed")
        {
            var pickedObject = UnityEditor.EditorGUIUtility.GetObjectPickerObject();
            if (pickedObject != null)
            {
                int insertIndex = largeModePositionArrayProperty.arraySize;
                largeModePositionArrayProperty.InsertArrayElementAtIndex(insertIndex);

                var newElement = largeModePositionArrayProperty.GetArrayElementAtIndex(insertIndex);
                newElement.objectReferenceValue = pickedObject;
                return;
            }
        }

        UnityEngine.GUILayout.Space(UnityEditor.EditorGUIUtility.standardVerticalSpacing);

        using (new UnityEditor.EditorGUILayout.VerticalScope("box"))
        {
            UnityEditor.EditorGUILayout.PropertyField(multiPositionTypeProperty, new UnityEngine.GUIContent("Position Type: ", "Simple Mode: Only one position is used.\nLarge Mode: Children of AkAmbient with AkAmbientLargeModePositioner component will be used as position source for multi-positioning.\nMultiple Position Mode: Every AkAmbient using the same event will be used as position source for multi-positioning."));

            UnityEngine.GUILayout.Space(UnityEditor.EditorGUIUtility.standardVerticalSpacing);

            currentAttSphereOp          = (AttenuationSphereOptions)UnityEditor.EditorGUILayout.EnumPopup("Show Attenuation Sphere: ", currentAttSphereOp);
            attSphereProperties[target] = currentAttSphereOp;

            if (multiPositionTypeProperty.intValue == (int)MultiPositionTypeLabel.Large_Mode)
            {
                UnityEngine.GUILayout.BeginHorizontal();
                if (UnityEngine.GUILayout.Button("Add Large Mode position object"))
                {
                    int insertIndex = largeModePositionArrayProperty.arraySize;
                    largeModePositionArrayProperty.InsertArrayElementAtIndex(insertIndex);

                    UnityEngine.GameObject newPoint = new UnityEngine.GameObject(string.Format("AkAmbientPoint{0}", insertIndex));
                    UnityEditor.Undo.RegisterCreatedObjectUndo(newPoint, "CreateNewLargeModePositionObject");
                    UnityEditor.Undo.AddComponent <AkAmbientLargeModePositioner>(newPoint);
                    UnityEditor.Undo.SetTransformParent(newPoint.transform, m_AkAmbient.transform, "CreateNewLargeModePositionObjectSetParent");
                    newPoint.transform.position   = m_AkAmbient.transform.TransformPoint(UnityEngine.Vector3.zero);
                    newPoint.transform.localScale = new UnityEngine.Vector3(1f, 1f, 1f);

                    var newElement = largeModePositionArrayProperty.GetArrayElementAtIndex(insertIndex);
                    newElement.objectReferenceValue = newPoint.GetComponent <AkAmbientLargeModePositioner>();
                }

                if (UnityEngine.GUILayout.Button("Pick existing position object"))
                {
                    int controlID = UnityEngine.GUIUtility.GetControlID(UnityEngine.FocusType.Passive);
                    UnityEditor.EditorGUIUtility.ShowObjectPicker <AkAmbientLargeModePositioner>(null, true, string.Empty, controlID);
                }
                UnityEngine.GUILayout.EndHorizontal();

                ++UnityEditor.EditorGUI.indentLevel;
                UnityEditor.EditorGUI.BeginChangeCheck();
                for (int i = 0; i < largeModePositionArrayProperty.arraySize; ++i)
                {
                    UnityEditor.EditorGUILayout.PropertyField(largeModePositionArrayProperty.GetArrayElementAtIndex(i), true);
                }
                if (UnityEditor.EditorGUI.EndChangeCheck())
                {
                    serializedObject.ApplyModifiedProperties();
                }
                --UnityEditor.EditorGUI.indentLevel;
            }
        }

        //Save multi-position type to know if it has changed
        var multiPosType = m_AkAmbient.multiPositionTypeLabel;

        if (m_AkAmbient.multiPositionTypeLabel == MultiPositionTypeLabel.MultiPosition_Mode)
        {
            UpdateTriggers(multiPosType);
        }
    }
        public static bool SearchAndProcessWwiseTypes(UnityEditor.SerializedProperty property)
        {
            var anyChange = false;
            var recurse   = false;

            for (var loop = property != null; loop; loop = property.Next(recurse))
            {
                recurse = false;

                if (property.isArray)
                {
                    if (property.arraySize == 0)
                    {
                        continue;
                    }

                    recurse = property.GetArrayElementAtIndex(0).propertyType == UnityEditor.SerializedPropertyType.Generic;
                }
                else if (property.propertyType == UnityEditor.SerializedPropertyType.Generic)
                {
                    recurse = true;

                    var wwiseObjectType = GetWwiseObjectType(property);
                    if (wwiseObjectType == WwiseObjectType.None)
                    {
                        continue;
                    }

                    // At this point, we know that the property's type's name is the same as one of our WwiseTypes.
                    var valueGuidProperty            = property.FindPropertyRelative("valueGuidInternal");
                    var wwiseObjectReferenceProperty = property.FindPropertyRelative("WwiseObjectReference");
                    if (valueGuidProperty == null || wwiseObjectReferenceProperty == null)
                    {
                        continue;
                    }

                    // At this point, we can be **pretty** sure that we are dealing with a WwiseType.
                    // The uncertainty lies with the fact that the property.type is the non-qualified name of the property's type.
                    recurse = false;

                    var idProperty = property.FindPropertyRelative("idInternal");
                    var hasChanged = false;
                    if (wwiseObjectType == WwiseObjectType.State || wwiseObjectType == WwiseObjectType.Switch)
                    {
                        var groupGuidProperty = property.FindPropertyRelative("groupGuidInternal");
                        if (groupGuidProperty == null)
                        {
                            continue;
                        }

                        var groupIdProperty = property.FindPropertyRelative("groupIdInternal");
                        hasChanged = ProcessDoubleGuidType(wwiseObjectReferenceProperty, wwiseObjectType, valueGuidProperty, idProperty, groupGuidProperty, groupIdProperty);
                    }
                    else
                    {
                        hasChanged = ProcessSingleGuidType(wwiseObjectReferenceProperty, wwiseObjectType, valueGuidProperty, idProperty);
                    }

                    anyChange = anyChange || hasChanged;
                }
            }

            return(anyChange);
        }
Example #19
0
        public void StartProcess(SVGAsset asset)
        {
            if (UnityEditor.EditorApplication.isPlayingOrWillChangePlaymode)
            {
                return;
            }

            if (errors == null)
            {
                errors = new List <SVGError>();
            }
            else
            {
                errors.Clear();
            }
            _importingSVG = true;

            UnityEditor.SerializedObject   svgAsset      = new UnityEditor.SerializedObject(asset);
            UnityEditor.SerializedProperty sharedMesh    = svgAsset.FindProperty("_sharedMesh");
            UnityEditor.SerializedProperty sharedShaders = svgAsset.FindProperty("_sharedShaders");

            Clear();
            SVGParser.Init();
            SVGGraphics.Init();
            atlasData = new SVGAtlasData();
            SVGElement _rootSVGElement = null;

#if IGNORE_EXCEPTIONS
            try {
#else
            Debug.LogWarning("Exceptions are turned on!");
#endif
                // Create new Asset
                CreateEmptySVGDocument();
                _rootSVGElement = this._svgDocument.rootElement;
#if IGNORE_EXCEPTIONS
            } catch (System.Exception exception) {
                _rootSVGElement = null;
                errors.Add(SVGError.Syntax);
                Debug.LogError("SVG Document Exception: " + exception.Message, asset);
            }
#endif

                if (_rootSVGElement == null)
                {
                    Debug.LogError("SVG Document is corrupted! " + UnityEditor.AssetDatabase.GetAssetPath(asset), asset);
                    _importingSVG = false;
                    return;
                }

                SVGGraphics.depthTree = new SVGDepthTree(_rootSVGElement.paintable.viewport);

#if IGNORE_EXCEPTIONS
                try {
#endif
                _rootSVGElement.Render();

                // Handle gradients
                bool hasGradients = (useGradients == SVGUseGradients.Always);

                // Create actual Mesh
                Shader[] outputShaders;
                SVGLayer[] outputLayers;
                Mesh mesh = SVGMesh.CombineMeshes(SVGGraphics.meshes, out outputLayers, out outputShaders, useGradients, format, compressDepth);
                if (mesh == null)
                {
                    return;
                }

                if (outputShaders != null)
                {
                    for (int i = 0; i < outputShaders.Length; i++)
                    {
                        if (outputShaders[i] == null)
                        {
                            continue;
                        }
                        if (outputShaders[i].name == SVGShader.GradientColorOpaque.name ||
                            outputShaders[i].name == SVGShader.GradientColorAlphaBlended.name)
                        {
                            hasGradients = true;
                            break;
                        }
                    }
                }

                Vector3[] vertices = mesh.vertices;
                Vector2 offset;
                Bounds bounds = mesh.bounds;
                Rect viewport = _rootSVGElement.paintable.viewport;
                viewport.x    *= SVGAssetImport.meshScale;
                viewport.y    *= SVGAssetImport.meshScale;
                viewport.size *= SVGAssetImport.meshScale;

                if (asset.ignoreSVGCanvas)
                {
                    offset = new Vector2(bounds.min.x + bounds.size.x * asset.pivotPoint.x,
                                         bounds.min.y + bounds.size.y * asset.pivotPoint.y);
                }
                else
                {
                    offset = new Vector2(viewport.min.x + viewport.size.x * asset.pivotPoint.x,
                                         viewport.min.y + viewport.size.y * asset.pivotPoint.y);
                }

                // Apply pivot point and Flip Y Axis
                for (int i = 0; i < vertices.Length; i++)
                {
                    vertices[i].x = vertices[i].x - offset.x;
                    vertices[i].y = (vertices[i].y - offset.y) * -1f;
                }

                mesh.vertices = vertices;
                mesh.RecalculateBounds();
                sharedMesh.objectReferenceValue = AddObjectToAsset <Mesh>(mesh, asset, HideFlags.HideInHierarchy);

//                Material sharedMaterial;
                if (outputShaders != null && outputShaders.Length > 0)
                {
                    sharedShaders.arraySize = outputShaders.Length;
                    if (hasGradients)
                    {
                        for (int i = 0; i < outputShaders.Length; i++)
                        {
                            sharedShaders.GetArrayElementAtIndex(i).stringValue = outputShaders[i].name;
                        }
                    }
                    else
                    {
                        for (int i = 0; i < outputShaders.Length; i++)
                        {
                            if (outputShaders[i].name == SVGShader.GradientColorAlphaBlended.name)
                            {
                                outputShaders[i] = SVGShader.SolidColorAlphaBlended;
                            }
                            else if (outputShaders[i].name == SVGShader.GradientColorOpaque.name)
                            {
                                outputShaders[i] = SVGShader.SolidColorOpaque;
                            }
                            sharedShaders.GetArrayElementAtIndex(i).stringValue = outputShaders[i].name;
                        }
                    }
                }

                // Serialize the Asset
                svgAsset.ApplyModifiedProperties();

                // Handle Canvas Rectangle
                System.Reflection.MethodInfo _editor_SetCanvasRectangle = typeof(SVGAsset).GetMethod("_editor_SetCanvasRectangle", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);
                _editor_SetCanvasRectangle.Invoke(asset, new object[] { new Rect(viewport.x, viewport.y, viewport.size.x, viewport.size.y) });

                if (asset.generateCollider)
                {
                    // Create polygon contour
                    if (SVGGraphics.paths != null && SVGGraphics.paths.Count > 0)
                    {
                        List <List <Vector2> > polygons = new List <List <Vector2> >();
                        for (int i = 0; i < SVGGraphics.paths.Count; i++)
                        {
                            Vector2[] points = SVGGraphics.paths[i].points;
                            for (int j = 0; j < points.Length; j++)
                            {
                                points[j].x = points[j].x * SVGAssetImport.meshScale - offset.x;
                                points[j].y = (points[j].y * SVGAssetImport.meshScale - offset.y) * -1f;
                            }

                            polygons.Add(new List <Vector2>(points));
                        }

                        polygons = SVGGeom.MergePolygon(polygons);

                        SVGPath[] paths = new SVGPath[polygons.Count];
                        for (int i = 0; i < polygons.Count; i++)
                        {
                            paths[i] = new SVGPath(polygons[i].ToArray());
                        }

                        System.Reflection.MethodInfo _editor_SetColliderShape = typeof(SVGAsset).GetMethod("_editor_SetColliderShape", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);
                        if (paths != null && paths.Length > 0)
                        {
                            _editor_SetColliderShape.Invoke(asset, new object[] { paths });
                        }
                        else
                        {
                            _editor_SetColliderShape.Invoke(asset, new object[] { null });
                        }
                    }
                }
                else
                {
                    System.Reflection.MethodInfo _editor_SetColliderShape = typeof(SVGAsset).GetMethod("_editor_SetColliderShape", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);
                    _editor_SetColliderShape.Invoke(asset, new object[] { null });
                }

                if (hasGradients)
                {
                    System.Reflection.MethodInfo _editor_SetGradients = typeof(SVGAsset).GetMethod("_editor_SetGradients", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);
                    if (atlasData.gradients != null && atlasData.gradients.Count > 0)
                    {
                        _editor_SetGradients.Invoke(asset, new object[] { atlasData.gradients.ToArray() });
                    }
                    else
                    {
                        _editor_SetGradients.Invoke(asset, new object[] { null });
                    }
                }
#if IGNORE_EXCEPTIONS
            } catch (System.Exception exception) {
                Debug.LogWarning("Asset: " + UnityEditor.AssetDatabase.GetAssetPath(asset) + " Failed to import\n" + exception.Message, asset);
                errors.Add(SVGError.CorruptedFile);
            }
#endif
                if (_svgDocument != null)
                {
                    _svgDocument.Clear();
                    _svgDocument = null;
                }
                Clear();

                UnityEditor.EditorUtility.SetDirty(asset);
                _importingSVG = false;
            }
Example #20
0
        public void StartProcess(SVGAsset asset)
        {
            if (UnityEditor.EditorApplication.isPlayingOrWillChangePlaymode)
            {
                return;
            }

            if (errors == null)
            {
                errors = new List <SVGError>();
            }
            else
            {
                errors.Clear();
            }
            _importingSVG = true;

            System.Reflection.FieldInfo _editor_runtimeMaterials = typeof(SVGAsset).GetField("_runtimeMaterials", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);
            _editor_runtimeMaterials.SetValue(asset, null);

            System.Reflection.FieldInfo _editor_runtimeMesh = typeof(SVGAsset).GetField("_runtimeMesh", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);
            _editor_runtimeMesh.SetValue(asset, null);

            UnityEditor.SerializedObject   svgAsset      = new UnityEditor.SerializedObject(asset);
            UnityEditor.SerializedProperty sharedMesh    = svgAsset.FindProperty("_sharedMesh");
            UnityEditor.SerializedProperty sharedShaders = svgAsset.FindProperty("_sharedShaders");

            Clear();
            SVGParser.Init();
            SVGGraphics.Init();
            atlasData = new SVGAtlasData();
            atlasData.Init(SVGAtlas.defaultAtlasTextureWidth * SVGAtlas.defaultAtlasTextureHeight);
            atlasData.AddGradient(SVGAtlasData.GetDefaultGradient());
            SVGElement _rootSVGElement = null;

#if IGNORE_EXCEPTIONS
            try {
#else
            Debug.LogWarning("Exceptions are turned on!");
#endif
                // Create new Asset
                CreateEmptySVGDocument();
                _rootSVGElement = this._svgDocument.rootElement;
#if IGNORE_EXCEPTIONS
            } catch (System.Exception exception) {
                _rootSVGElement = null;
                errors.Add(SVGError.Syntax);
                Debug.LogError("SVG Document Exception: " + exception.Message, asset);
            }
#endif

                if (_rootSVGElement == null)
                {
                    Debug.LogError("SVG Document is corrupted! " + UnityEditor.AssetDatabase.GetAssetPath(asset), asset);
                    _importingSVG = false;
                    return;
                }

#if IGNORE_EXCEPTIONS
                try {
#endif
                _rootSVGElement.Render();

                Rect viewport = _rootSVGElement.paintable.viewport;
                viewport.x    *= SVGAssetImport.meshScale;
                viewport.y    *= SVGAssetImport.meshScale;
                viewport.size *= SVGAssetImport.meshScale;

                Vector2 offset;
                SVGGraphics.CorrectSVGLayers(SVGGraphics.layers, viewport, asset, out offset);

                // Handle gradients
                bool hasGradients = false;

                // Create actual Mesh
                Shader[] outputShaders;
                Mesh mesh = new Mesh();
                SVGMesh.CombineMeshes(SVGGraphics.layers.ToArray(), mesh, out outputShaders, useGradients, format, compressDepth, asset.antialiasing);
                if (mesh == null)
                {
                    return;
                }

                if (useGradients == SVGUseGradients.Always)
                {
                    if (outputShaders != null)
                    {
                        for (int i = 0; i < outputShaders.Length; i++)
                        {
                            if (outputShaders[i] == null)
                            {
                                continue;
                            }
                            if (outputShaders[i].name == SVGShader.SolidColorOpaque.name)
                            {
                                outputShaders[i] = SVGShader.GradientColorOpaque;
                            }
                            else if (outputShaders[i].name == SVGShader.SolidColorAlphaBlended.name)
                            {
                                outputShaders[i] = SVGShader.GradientColorAlphaBlended;
                            }
                            else if (outputShaders[i].name == SVGShader.SolidColorAlphaBlendedAntialiased.name)
                            {
                                outputShaders[i] = SVGShader.GradientColorAlphaBlendedAntialiased;
                            }
                        }
                    }
                    hasGradients = true;
                }
                else
                {
                    if (outputShaders != null)
                    {
                        for (int i = 0; i < outputShaders.Length; i++)
                        {
                            if (outputShaders[i] == null)
                            {
                                continue;
                            }
                            if (outputShaders[i].name == SVGShader.GradientColorOpaque.name ||
                                outputShaders[i].name == SVGShader.GradientColorAlphaBlended.name ||
                                outputShaders[i].name == SVGShader.GradientColorAlphaBlendedAntialiased.name ||
                                outputShaders[i].name == SVGShader.GradientColorAlphaBlendedAntialiasedCompressed.name)
                            {
                                hasGradients = true;
                                break;
                            }
                        }
                    }
                }

                if (!asset.useLayers)
                {
                    sharedMesh.objectReferenceValue = AddObjectToAsset <Mesh>(mesh, asset, HideFlags.HideInHierarchy);
                }

//                Material sharedMaterial;
                if (outputShaders != null && outputShaders.Length > 0)
                {
                    sharedShaders.arraySize = outputShaders.Length;
                    if (hasGradients)
                    {
                        for (int i = 0; i < outputShaders.Length; i++)
                        {
                            sharedShaders.GetArrayElementAtIndex(i).stringValue = outputShaders[i].name;
                        }
                    }
                    else
                    {
                        for (int i = 0; i < outputShaders.Length; i++)
                        {
                            if (outputShaders[i].name == SVGShader.GradientColorAlphaBlended.name)
                            {
                                outputShaders[i] = SVGShader.SolidColorAlphaBlended;
                            }
                            else if (outputShaders[i].name == SVGShader.GradientColorOpaque.name)
                            {
                                outputShaders[i] = SVGShader.SolidColorOpaque;
                            }
                            sharedShaders.GetArrayElementAtIndex(i).stringValue = outputShaders[i].name;
                        }
                    }
                }

                // Serialize the Asset
                svgAsset.ApplyModifiedProperties();

                // Handle Canvas Rectangle
                System.Reflection.MethodInfo _editor_SetCanvasRectangle = typeof(SVGAsset).GetMethod("_editor_SetCanvasRectangle", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);
                _editor_SetCanvasRectangle.Invoke(asset, new object[] { new Rect(viewport.x, viewport.y, viewport.size.x, viewport.size.y) });

                if (asset.generateCollider)
                {
                    // Create polygon contour
                    if (SVGGraphics.paths != null && SVGGraphics.paths.Count > 0)
                    {
                        List <List <Vector2> > polygons = new List <List <Vector2> >();
                        for (int i = 0; i < SVGGraphics.paths.Count; i++)
                        {
                            Vector2[] points = SVGGraphics.paths[i].points;
                            for (int j = 0; j < points.Length; j++)
                            {
                                points[j].x = points[j].x * SVGAssetImport.meshScale - offset.x;
                                points[j].y = (points[j].y * SVGAssetImport.meshScale + offset.y) * -1f;
                            }

                            polygons.Add(new List <Vector2>(points));
                        }

                        polygons = SVGGeom.MergePolygon(polygons);

                        SVGPath[] paths = new SVGPath[polygons.Count];
                        for (int i = 0; i < polygons.Count; i++)
                        {
                            paths[i] = new SVGPath(polygons[i].ToArray());
                        }

                        System.Reflection.MethodInfo _editor_SetColliderShape = typeof(SVGAsset).GetMethod("_editor_SetColliderShape", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);
                        if (paths != null && paths.Length > 0)
                        {
                            _editor_SetColliderShape.Invoke(asset, new object[] { paths });
                        }
                        else
                        {
                            _editor_SetColliderShape.Invoke(asset, new object[] { null });
                        }
                    }
                }
                else
                {
                    System.Reflection.MethodInfo _editor_SetColliderShape = typeof(SVGAsset).GetMethod("_editor_SetColliderShape", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);
                    _editor_SetColliderShape.Invoke(asset, new object[] { null });
                }

                System.Reflection.MethodInfo _editor_SetGradients = typeof(SVGAsset).GetMethod("_editor_SetGradients", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);
                _editor_SetGradients.Invoke(asset, new object[] { null });
                if (hasGradients)
                {
                    if (atlasData.gradientCache != null && atlasData.gradientCache.Count > 0)
                    {
                        int          gradientsCount = SVGAssetImport.atlasData.gradientCache.Count;
                        CCGradient[] gradients      = new CCGradient[gradientsCount];
                        int          i = 0;
                        foreach (KeyValuePair <string, CCGradient> entry in SVGAssetImport.atlasData.gradientCache)
                        {
                            gradients[i++] = entry.Value;
                        }
                        _editor_SetGradients.Invoke(asset, new object[] { gradients });
                    }
                }

                System.Reflection.MethodInfo _editor_SetLayers = typeof(SVGAsset).GetMethod("_editor_SetLayers", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);
                _editor_SetLayers.Invoke(asset, new object[] { null });
                if (asset.useLayers)
                {
                    if (SVGGraphics.layers != null && SVGGraphics.layers.Count > 0)
                    {
                        _editor_SetLayers.Invoke(asset, new object[] { SVGGraphics.layers.ToArray() });
                    }
                }

#if IGNORE_EXCEPTIONS
            } catch (System.Exception exception) {
                Debug.LogWarning("Asset: " + UnityEditor.AssetDatabase.GetAssetPath(asset) + " Failed to import\n" + exception.Message, asset);
                errors.Add(SVGError.CorruptedFile);
            }
#endif
                if (_svgDocument != null)
                {
                    _svgDocument.Clear();
                    _svgDocument = null;
                }
                Clear();

                UnityEditor.EditorUtility.SetDirty(asset);
                _importingSVG = false;
            }
Example #21
0
    public override void OnInspectorGUI()
    {
        serializedObject.Update();

        using (new UnityEngine.GUILayout.VerticalScope("box"))
        {
            for (var i = 0; i < AkEnvironmentPortal.MAX_ENVIRONMENTS_PER_PORTAL; i++)
            {
                var list   = m_envList.GetArrayElementAtIndex(i).FindPropertyRelative("list");
                var labels = new string[list.arraySize];

                for (var j = 0; j < list.arraySize; j++)
                {
                    var environment = list.GetArrayElementAtIndex(j).objectReferenceValue as AkEnvironment;
                    if (environment != null)
                    {
                        labels[j] = j + 1 + ". " + GetEnvironmentName(environment) + " (" + environment.name + ")";
                    }
                    else
                    {
                        list.DeleteArrayElementAtIndex(j);
                    }
                }

                var index = UnityEditor.EditorGUILayout.Popup("Environment #" + (i + 1), m_selectedIndex[i], labels);
                m_environments.GetArrayElementAtIndex(i).objectReferenceValue = index < 0 || index >= list.arraySize ? null : list.GetArrayElementAtIndex(index).objectReferenceValue;
                m_selectedIndex[i] = index;
            }
        }

        UnityEngine.GUILayout.Space(UnityEditor.EditorGUIUtility.standardVerticalSpacing);

        using (new UnityEditor.EditorGUILayout.VerticalScope("box"))
        {
            var axisLabels = new[] { "X", "Y", "Z" };
            var axes       = new[] { UnityEngine.Vector3.right, UnityEngine.Vector3.up, UnityEngine.Vector3.forward };

            var index = 0;
            for (var i = 0; i < 3; i++)
            {
                if (m_axis.vector3Value == axes[i])
                {
                    index = i;
                    break;
                }
            }

            var newIndex = UnityEditor.EditorGUILayout.Popup("Axis", index, axisLabels);
            m_axis.vector3Value = axes[newIndex];

            if (index != newIndex)
            {
                for (var i = 0; i < AkEnvironmentPortal.MAX_ENVIRONMENTS_PER_PORTAL; i++)
                {
                    m_envList.GetArrayElementAtIndex(i).FindPropertyRelative("list").ClearArray();
                }

                FindOverlappingEnvironments();
            }
        }

        serializedObject.ApplyModifiedProperties();

        AkGameObjectInspector.RigidbodyCheck(m_envPortal.gameObject);
    }