private void SetGuid(AK.Wwise.TreeView.TreeViewItem in_item)
    {
        m_serializedObject.Update();

        var obj = in_item.DataContext as AkWwiseTreeView.AkTreeInfo;

        //we set the items guid
        AkUtilities.SetByteArrayProperty(m_selectedItemGuid[0], obj.Guid);
        if (m_selectedItemID != null)
        {
            m_selectedItemID[0].intValue = obj.ID;
        }

        //When its a State or a Switch, we set the group's guid
        if (m_selectedItemGuid.Length == 2)
        {
            obj = in_item.Parent.DataContext as AkWwiseTreeView.AkTreeInfo;
            AkUtilities.SetByteArrayProperty(m_selectedItemGuid[1], obj.Guid);
            if (m_selectedItemID != null)
            {
                m_selectedItemID[1].intValue = obj.ID;
            }
        }

        m_serializedObject.ApplyModifiedProperties();
    }
Esempio n. 2
0
        void GetMeshes()
        {
            if (m_Prepared)
            {
                UnityEditor.EditorUtility.DisplayDialog("Error", "Make sure is default state and not check prepared", "OK");
                return;
            }
            UnityEditor.SerializedObject target = new UnityEditor.SerializedObject(this);
            target.Update();
            var skin = target.FindProperty("m_LodSkins");

            skin.ClearArray();
            //if(skin.arraySize == 0)
            {
                var meshes = GetComponentsInChildren <SkinnedMeshRenderer>();
                for (int i = 0; i < meshes.Length; i++)
                {
                    skin.InsertArrayElementAtIndex(i);
                    var pro = skin.GetArrayElementAtIndex(i).FindPropertyRelative("m_Mesh");
                    pro.objectReferenceValue = meshes[i];
                    pro = skin.GetArrayElementAtIndex(i).FindPropertyRelative("m_RootBone");
                    pro.objectReferenceValue = meshes[i].rootBone;
                }
            }
            target.ApplyModifiedProperties();
        }
Esempio n. 3
0
        public void DestroyHardwarePlayer()
        {
            if (_hardwarePlayer == null)
            {
                return;
            }

            // Get SerializedProperty objects
            UnityEditor.SerializedObject serializedObject = GetSerializedObject();
            serializedObject.Update();
            UnityEditor.SerializedProperty hardwarePlayerProperty = serializedObject.FindProperty("_hardwarePlayer");

            if (UnityEditor.EditorUtility.DisplayDialog("Heyo, be careful here!", "Is it cool if I destroy the [Camera Rig] instance to make room for a shiny new one?\r\n\r\nAll of your scripts /should/ be on \"Player (Hardware)\", but rules are made to be broken right?\r\n\r\nIf you put some custom stuff on [Camera Rig], that's cool, I won't judge, but hit \"Leave in Place\" to keep it in the scene, otherwise, hit \"Destroy!\" bb.", "Destroy!", "Leave in Place"))
            {
                _hardwarePlayer.DestroyDependencies();
                DestroyImmediate(_hardwarePlayer);
            }
            else
            {
                _hardwarePlayer.DisableDependencies();
                _hardwarePlayer.enabled = false;
            }
            hardwarePlayerProperty.objectReferenceValue = null;

            // Apply Changes
            serializedObject.ApplyModifiedPropertiesWithoutUndo();
        }
 private void EditorSelect(GameObject obj)
 {
                 #if UNITY_EDITOR
     for (int i = 0; i < objects.Count; i++)
     {
         if (objects [i])
         {
             var so = new UnityEditor.SerializedObject(objects[i]);
             so.Update();
             so.FindProperty("m_IsActive").boolValue = objects [i] == obj;
             so.ApplyModifiedProperties();
         }
     }
                 #endif
 }
Esempio n. 5
0
        internal void UpdateMarkerSize(Vector2 markerSize)
        {
#if UNITY_EDITOR
            if (!ValidateMarkerRenderer())
            {
                return;
            }

            // We do the transform scale modification in order to trigger a SimulatedObject refresh
            // to be able to update the Bounds of the synthetic marker in the MARS Database
            m_MarkerRendererSerializedObjectTransform.Update();
            m_MarkerRendererTransformLocalScaleProperty.vector3Value = new Vector3(markerSize.x, 0.01f, markerSize.y);
            m_MarkerRendererSerializedObjectTransform.ApplyModifiedProperties();
#endif
        }
Esempio n. 6
0
        void Start()
        {
            if (UnityEditor.PrefabUtility.IsPartOfPrefabInstance(this) == false)
            {
                return;
            }

            string     teleportAssetPath = UnityEditor.PrefabUtility.GetPrefabAssetPathOfNearestInstanceRoot(this);
            GameObject teleportPrefab    = UnityEditor.AssetDatabase.LoadAssetAtPath <GameObject>(teleportAssetPath);

            Teleport teleport = teleportPrefab.GetComponent <Teleport>();

            UnityEditor.SerializedObject serializedTeleport = new UnityEditor.SerializedObject(teleport);
            serializedTeleport.Update();
            bool changed = false;

            changed |= FindURPVersion(serializedTeleport, "areaHighlightedMaterial");

            changed |= FindURPVersion(serializedTeleport, "areaLockedMaterial");

            changed |= FindURPVersion(serializedTeleport, "areaVisibleMaterial");

            changed |= FindURPVersion(serializedTeleport, "pointHighlightedMaterial");

            changed |= FindURPVersion(serializedTeleport, "pointLockedMaterial");

            changed |= FindURPVersion(serializedTeleport, "pointVisibleMaterial");

            if (changed)
            {
                serializedTeleport.ApplyModifiedProperties();
                UnityEditor.EditorUtility.SetDirty(teleport);
            }

            TeleportArc arc = teleportPrefab.GetComponent <TeleportArc>();

            UnityEditor.SerializedObject serializedArc = new UnityEditor.SerializedObject(arc);
            serializedArc.Update();

            changed = FindURPVersion(serializedArc, "material");

            if (changed)
            {
                serializedArc.ApplyModifiedProperties();
                UnityEditor.EditorUtility.SetDirty(arc);
            }
        }
Esempio n. 7
0
        // Hardware Config
        public void CreateHardwarePlayer(Type hardwarePlayerClass)
        {
            // Destroy existing hardware player if needed
            DestroyHardwarePlayer();

            if (!hardwarePlayerClass.IsSubclassOf(typeof(Hardware.HardwarePlayer)))
            {
                UnityEditor.EditorUtility.DisplayDialog("Error", "Attempting to configure Hardware using class that doesn't derive from Normal.Hardware.HardwarePlayer. Bailing.", "OK");
                return;
            }

            // Get SerializedProperty objects
            UnityEditor.SerializedObject serializedObject = GetSerializedObject();
            serializedObject.Update();
            UnityEditor.SerializedProperty hardwarePlayerProperty           = serializedObject.FindProperty("_hardwarePlayer");
            UnityEditor.SerializedProperty hardwarePlayerGameObjectProperty = serializedObject.FindProperty("_hardwarePlayerGameObject");

            // Create hardware player game object if it doesn't exist yet.
            if (_hardwarePlayerGameObject == null)
            {
                _hardwarePlayerGameObject = new GameObject("Player (Hardware)");
                _hardwarePlayerGameObject.transform.SetParent(transform, false);
                hardwarePlayerGameObjectProperty.objectReferenceValue = _hardwarePlayerGameObject;
            }

            // If there's an existing hardware player component, enable it. Otherwise create it.
            _hardwarePlayer = (Hardware.HardwarePlayer)_hardwarePlayerGameObject.GetComponent(hardwarePlayerClass);
            if (_hardwarePlayer != null)
            {
                _hardwarePlayer.enabled = true;
                _hardwarePlayer.EnableDependencies();
            }
            else
            {
                _hardwarePlayer = (Hardware.HardwarePlayer)_hardwarePlayerGameObject.AddComponent(hardwarePlayerClass);
                _hardwarePlayer.CreateDependencies();
            }
            hardwarePlayerProperty.objectReferenceValue = _hardwarePlayer;

            // Apply Changes
            serializedObject.ApplyModifiedPropertiesWithoutUndo();
        }
        protected virtual void OnValidate()
        {
            // change old DeviceRole value to viveRole value
            var serializedObject = new UnityEditor.SerializedObject(this);

            var roleValueProp = serializedObject.FindProperty("role");
            var oldRoleValue  = roleValueProp.intValue;

            if (oldRoleValue != (int)DeviceRole.Invalid)
            {
                Type newRoleType;
                int  newRoleValue;

                if (oldRoleValue == -1)
                {
                    newRoleType  = typeof(DeviceRole);
                    newRoleValue = (int)DeviceRole.Hmd;
                }
                else
                {
                    newRoleType  = typeof(HandRole);
                    newRoleValue = oldRoleValue;
                }

                if (Application.isPlaying)
                {
                    roleValueProp.intValue = (int)DeviceRole.Invalid;
                    m_viveRole.Set(newRoleType, newRoleValue);
                }
                else
                {
                    roleValueProp.intValue = (int)DeviceRole.Invalid;
                    serializedObject.ApplyModifiedProperties();
                    m_viveRole.Set(newRoleType, newRoleValue);
                    serializedObject.Update();
                }
            }
            serializedObject.Dispose();
        }
        protected override void OnValidate()
        {
            base.OnValidate();

            // convert legacy buttonEventSource property to ViveRoleProperty
            var serializedObject = new UnityEditor.SerializedObject(this);
            var btnEventSrcProp  = serializedObject.FindProperty("buttonEventSource");
            var btnEventSrc      = btnEventSrcProp.intValue;

            if (btnEventSrc != 3) // ButtonEventSource.None
            {
                btnEventSrcProp.intValue = 3;

                if (!Application.isPlaying)
                {
                    serializedObject.ApplyModifiedProperties();
                }

                switch (btnEventSrc)
                {
                case 2:
                    viveRole.SetEx(HandRole.LeftHand);
                    break;

                case 0:
                case 1:
                default:
                    viveRole.SetEx(HandRole.RightHand);
                    break;
                }

                if (!Application.isPlaying)
                {
                    serializedObject.Update();
                }
            }
            serializedObject.Dispose();
        }
Esempio n. 10
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
        }
Esempio n. 11
0
        private void Rebuild2DCGCollider()
        {
            try {
                Init();
                if (!initialized)
                {
                    return;
                }

                float ppu = GetPPU();                                                   // get pixels per unit from GameSettings
                SpriteFactory.SF2DColliderGenHelper.Data data = script.CheckCollider(); // get the data we need from the helper script
                if (data == null)
                {
                    throw new System.Exception();
                }


                UnityEngine.Component alphaMeshCollider = script.GetComponent("AlphaMeshCollider");
                if (alphaMeshCollider == null)
                {
                    throw new System.Exception("No AlphaMeshCollider component was found on Sprite! If you have removed the 2D Collider Gen collider, please remove the helper component");
                }
                System.Type type_alphaMeshCollider = alphaMeshCollider.GetType();

                // Verify the 2D Collider Gen fields we need exist
                Verify2DCGFields(type_alphaMeshCollider);

                // Get the serialized objects
                UnityEditor.SerializedObject   so = new UnityEditor.SerializedObject(alphaMeshCollider);
                UnityEditor.SerializedProperty sp;
                so.Update();

                // CUSTOM TEX
                sp = so.FindProperty("mRegionIndependentParameters.mCustomTex");
                if (sp == null)
                {
                    FieldException("Required field not found!");
                }

                UnityEngine.Texture2D tex = FindFrameTexture(data.masterSprite);
                if (tex == null)
                {
                    UnityEngine.Debug.LogWarning("Frame texture not found! 2D Collider Gen mesh collider will not generate correctly.");
                }
                sp.objectReferenceValue = tex;

                // CUSTOM SCALE
                sp = so.FindProperty("mRegionIndependentParameters.mCustomScale");
                if (sp == null)
                {
                    FieldException("Required field not found!");
                }

                UnityEngine.Vector2 scale = data.pixelScale / ppu; // convert pixel scale to units
                sp.vector2Value = scale;                           // update scale

                // FLIP
                UnityEngine.Vector2 offset = data.unitOffset; // get offset which is affected by flip

                // FLIP X
                sp = so.FindProperty("mRegionIndependentParameters.mFlipHorizontal");
                if (sp == null)
                {
                    FieldException("Required field not found!");
                }

                if (sp.boolValue != data.isFlippedX)
                {
                    sp.boolValue = data.isFlippedX;
                }
                if (data.isFlippedX)
                {
                    offset.x *= -1.0f;
                }

                // FLIP Y
                sp = so.FindProperty("mRegionIndependentParameters.mFlipVertical");
                if (sp == null)
                {
                    FieldException("Required field not found!");
                }

                if (sp.boolValue != data.isFlippedY)
                {
                    sp.boolValue = data.isFlippedY;
                }
                if (data.isFlippedY)
                {
                    offset.y *= -1.0f;
                }

                // CUSTOM OFFSET
                sp = so.FindProperty("mRegionIndependentParameters.mCustomOffset");
                if (sp == null)
                {
                    FieldException("Required field not found!");
                }

                sp.vector3Value = offset; // update offset

                // Finish up with the serialized object
                so.ApplyModifiedProperties();

                // Rebuild the 2DCG collider
                type_alphaMeshCollider.InvokeMember("RecalculateCollider", System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.InvokeMethod, null, alphaMeshCollider, null);
            } catch (System.Exception e) {
                UnityEngine.Debug.LogError(e.Message);
                UnityEngine.Debug.LogError("STACK TRACE: " + e.StackTrace);
            }
        }
        private void Rebuild2DCGCollider()
        {
            try {
                Init();
                if(!initialized) return;

                float ppu = GetPPU(); // get pixels per unit from GameSettings
                SpriteFactory.SF2DColliderGenHelper.Data data = script.CheckCollider(); // get the data we need from the helper script
                if(data == null) throw new System.Exception();

                UnityEngine.Component alphaMeshCollider = script.GetComponent("AlphaMeshCollider");
                if(alphaMeshCollider == null) throw new System.Exception("No AlphaMeshCollider component was found on Sprite! If you have removed the 2D Collider Gen collider, please remove the helper component");
                System.Type type_alphaMeshCollider = alphaMeshCollider.GetType();

                // Verify the 2D Collider Gen fields we need exist
                Verify2DCGFields(type_alphaMeshCollider);

                // Get the serialized objects
                UnityEditor.SerializedObject so = new UnityEditor.SerializedObject(alphaMeshCollider);
                UnityEditor.SerializedProperty sp;
                so.Update();

                // CUSTOM TEX
                sp = so.FindProperty("mRegionIndependentParameters.mCustomTex");
                if(sp == null) FieldException("Required field not found!");

                UnityEngine.Texture2D tex = FindFrameTexture(data.masterSprite);
                if(tex == null) {
                    UnityEngine.Debug.LogWarning("Frame texture not found! 2D Collider Gen mesh collider will not generate correctly.");
                }
                sp.objectReferenceValue = tex;

                // CUSTOM SCALE
                sp = so.FindProperty("mRegionIndependentParameters.mCustomScale");
                if(sp == null) FieldException("Required field not found!");

                UnityEngine.Vector2 scale = data.pixelScale / ppu; // convert pixel scale to units
                sp.vector2Value = scale; // update scale

                // FLIP
                UnityEngine.Vector2 offset = data.unitOffset; // get offset which is affected by flip

                // FLIP X
                sp = so.FindProperty("mRegionIndependentParameters.mFlipHorizontal");
                if(sp == null) FieldException("Required field not found!");

                if(sp.boolValue != data.isFlippedX) sp.boolValue = data.isFlippedX;
                if(data.isFlippedX) {
                    offset.x *= -1.0f;
                }

                // FLIP Y
                sp = so.FindProperty("mRegionIndependentParameters.mFlipVertical");
                if(sp == null) FieldException("Required field not found!");

                if(sp.boolValue != data.isFlippedY) sp.boolValue = data.isFlippedY;
                if(data.isFlippedY) {
                    offset.y *= -1.0f;
                }

                // CUSTOM OFFSET
                sp = so.FindProperty("mRegionIndependentParameters.mCustomOffset");
                if(sp == null) FieldException("Required field not found!");

                sp.vector3Value = offset; // update offset

                // Finish up with the serialized object
                so.ApplyModifiedProperties();

                // Rebuild the 2DCG collider
                type_alphaMeshCollider.InvokeMember("RecalculateCollider", System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.InvokeMethod, null, alphaMeshCollider, null);

            } catch(System.Exception e) {
                UnityEngine.Debug.LogError(e.Message);
                UnityEngine.Debug.LogError("STACK TRACE: " + e.StackTrace);
            }
        }