Пример #1
0
 /// <summary>
 /// Draws the add-on inspector.
 /// </summary>
 public override void DrawInspector()
 {
     ManagerUtility.DrawControlBox("Scene Setup", DrawSceneSetup, "Adds the PUN objects to your scene. These objects should be added to each PUN room.", true, "Setup Scene",
                                   SetupScene, "The scene objects were added successfully.");
     ManagerUtility.DrawControlBox("Object Setup", DrawObjectSelection, "Adds the PUN component to the character, projectile, grenade, health, respawner, " +
                                   "moving platform, or interactable object.",
                                   IsValidObject(), "Setup Object", SetupObject, "The object was setup successfully.");
 }
Пример #2
0
        /// <summary>
        /// Sets up the room to work with Photon PUN.
        /// </summary>
        private void SetupScene()
        {
            // Create the pun components if they doesn't already exists.
            GameObject punGameObject;

            StateSystem.PunStateManager stateManager;
            if ((stateManager = GameObject.FindObjectOfType <StateSystem.PunStateManager>()) == null)
            {
                punGameObject = new GameObject("PunGame");
            }
            else
            {
                punGameObject = stateManager.gameObject;
            }

            // Add the Singletons.
            InspectorUtility.AddComponent <Game.PunObjectPool>(punGameObject);
            InspectorUtility.AddComponent <Game.RuntimePickups>(punGameObject);
            InspectorUtility.AddComponent <Game.SingleCharacterSpawnManager>(punGameObject);
            var itemTypeTracker = InspectorUtility.AddComponent <Game.ItemTypeTracker>(punGameObject);

            if (itemTypeTracker.ItemCollection == null)
            {
                itemTypeTracker.ItemCollection = ManagerUtility.FindItemCollection(m_MainManagerWindow);
            }
            InspectorUtility.AddComponent <StateSystem.PunStateManager>(punGameObject);

            // The camera controller should not initialize the character on awake.
            var cameraController = GameObject.FindObjectOfType <Camera.CameraController>();

            if (cameraController != null)
            {
                cameraController.InitCharacterOnAwake = false;
            }

            // The SceneObjectIdentifier should be added to every collider within the scene.
            if (m_AddSceneIdentifiers)
            {
                var sceneObjectID = 1;
                var colliders     = GameObject.FindObjectsOfType <Collider>();
                for (int i = 0; i < colliders.Length; ++i)
                {
                    if (colliders[i].isTrigger || colliders[i].gameObject.scene.rootCount == 0 || colliders[i].GetComponent <PhotonView>() != null)
                    {
                        continue;
                    }

                    // The ID should be unique within the scene.
                    var sceneObjectIdentifier = InspectorUtility.AddComponent <Objects.SceneObjectIdentifier>(colliders[i].gameObject);
                    sceneObjectIdentifier.ID = sceneObjectID;
                    sceneObjectID++;

                    InspectorUtility.SetDirty(sceneObjectIdentifier);
                }
            }
        }
Пример #3
0
        public async Task <IEnumerable <MALAnime> > AnimeQuery(string str)
        {
            try
            {
                // Generate anime query string
                string param      = StringToQueryParameter(str);
                string requestUrl = "http://myanimelist.net/api/anime/search.xml?q=" + param;

                // Await get response
                //var response = await httpClient.GetAsync(requestUrl, HttpCompletionOption.ResponseContentRead);
                //var resString = await response.Content.ReadAsStringAsync();
                var resString = await ManagerUtility.Query(requestUrl, this);

                // Create xml document
                var document = new XmlDocument();
                document.LoadXml(resString);      // Read the xml data from the string

                // DEBUG!!!
                // Get the root node in the xml
                var root = document.DocumentElement;

                // Create a queryable animes object
                var animeList = new List <MALAnime>();

                foreach (var child in root)
                {
                    var c = child as XmlNode;

                    // If the node is an entry node
                    if (c.Name == "entry")
                    {
                        animeList.Add(GetAnimeFromEntry(c));    // Add the anime underlying anime data to the list
                    }
                }

                // Return the queryable animes object
                return((IEnumerable <MALAnime>)animeList);
            }
            catch (Exception ex)
            {
                Debug.WriteLine("Exception: " + ex.Message);
            }

            return(null);
        }
Пример #4
0
        /// <summary>
        /// Finds the Item Collection.
        /// </summary>
        protected override void OnEnable()
        {
            base.OnEnable();

            m_ItemCollection = ManagerUtility.FindItemCollection(this);
        }
Пример #5
0
        /// <summary>
        /// Removes the objects specified by the object references object.
        /// </summary>
        private static void ProcessObjectReferences(ObjectReferences objectReferences, bool fromScene)
        {
            if (objectReferences == null)
            {
                return;
            }

            RemoveObjects(objectReferences.RemoveObjects);
            objectReferences.RemoveObjects = null;
#if !FIRST_PERSON_CONTROLLER
            RemoveObjects(objectReferences.FirstPersonObjects);
            objectReferences.FirstPersonObjects = null;
#endif
#if !THIRD_PERSON_CONTROLLER
            RemoveObjects(objectReferences.ThirdPersonObjects);
            objectReferences.ThirdPersonObjects = null;
#endif
#if !ULTIMATE_CHARACTER_CONTROLLER_SHOOTER
            RemoveObjects(objectReferences.ShooterObjects);
            objectReferences.ShooterObjects = null;
#endif
#if !ULTIMATE_CHARACTER_CONTROLLER_MELEE
            RemoveObjects(objectReferences.MeleeObjects);
            objectReferences.MeleeObjects = null;
#endif

#if !FIRST_PERSON_CONTROLLER || !THIRD_PERSON_CONTROLLER
            // Remove any view types and states that are no longer valid.
            Opsive.UltimateCharacterController.Camera.CameraController cameraController;
            if (fromScene)
            {
                cameraController = GameObject.FindObjectOfType <UltimateCharacterController.Camera.CameraController>();
            }
            else
            {
                cameraController = objectReferences.GetComponent <UltimateCharacterController.Camera.CameraController>();
            }
            if (cameraController != null)
            {
                cameraController.DeserializeViewTypes();
                var viewTypes = new List <ViewType>(cameraController.ViewTypes);
                for (int i = viewTypes.Count - 1; i > -1; --i)
                {
                    if (viewTypes[i] == null)
                    {
                        viewTypes.RemoveAt(i);
                        continue;
                    }
                    viewTypes[i].States = RemoveUnusedStates(viewTypes[i].States);
                }
                cameraController.ViewTypeData = Serialization.Serialize <ViewType>(viewTypes);
                cameraController.ViewTypes    = viewTypes.ToArray();
                InspectorUtility.SetDirty(cameraController);
            }

            // Remove any movement types and states that are no longer valid.
            Character.UltimateCharacterLocomotion characterLocomotion;
            if (fromScene)
            {
                characterLocomotion = GameObject.FindObjectOfType <Character.UltimateCharacterLocomotion>();
            }
            else
            {
                characterLocomotion = objectReferences.GetComponent <Character.UltimateCharacterLocomotion>();
            }
            if (characterLocomotion != null)
            {
                characterLocomotion.DeserializeMovementTypes();
                var movementTypes = new List <MovementType>(characterLocomotion.MovementTypes);
                for (int i = movementTypes.Count - 1; i > -1; --i)
                {
                    if (movementTypes[i] == null)
                    {
                        movementTypes.RemoveAt(i);
                        continue;
                    }
                    movementTypes[i].States = RemoveUnusedStates(movementTypes[i].States);
                }
                characterLocomotion.MovementTypeData = Serialization.Serialize <MovementType>(movementTypes);
                characterLocomotion.MovementTypes    = movementTypes.ToArray();
#if FIRST_PERSON_CONTROLLER
                characterLocomotion.SetMovementType(UltimateCharacterController.Utility.UnityEngineUtility.GetType(characterLocomotion.FirstPersonMovementTypeFullName));
#else
                characterLocomotion.SetMovementType(UltimateCharacterController.Utility.UnityEngineUtility.GetType(characterLocomotion.ThirdPersonMovementTypeFullName));
#endif

                // Ensure the animator is pointing to the correct reference.
                var animator = characterLocomotion.GetComponent <Animator>();
                if (animator != null && animator.runtimeAnimatorController == null)
                {
                    animator.runtimeAnimatorController = ManagerUtility.FindAnimatorController(null);
                    InspectorUtility.SetDirty(animator);
                }

                // Check for unused ability states.
                var abilities = new List <Ability>(characterLocomotion.GetSerializedAbilities());
                for (int i = abilities.Count - 1; i > -1; --i)
                {
                    if (abilities[i] == null)
                    {
                        abilities.RemoveAt(i);
                        continue;
                    }
                    abilities[i].States = RemoveUnusedStates(abilities[i].States);
                }
                characterLocomotion.AbilityData = Serialization.Serialize <Ability>(abilities);
                characterLocomotion.Abilities   = abilities.ToArray();

                // Check for unused item ability states.
                var itemAbilities = new List <ItemAbility>(characterLocomotion.GetSerializedItemAbilities());
                for (int i = itemAbilities.Count - 1; i > -1; --i)
                {
                    if (itemAbilities[i] == null)
                    {
                        itemAbilities.RemoveAt(i);
                        continue;
                    }
                    itemAbilities[i].States = RemoveUnusedStates(itemAbilities[i].States);
                }
                characterLocomotion.ItemAbilityData = Serialization.Serialize <ItemAbility>(itemAbilities);
                characterLocomotion.ItemAbilities   = itemAbilities.ToArray();
                InspectorUtility.SetDirty(characterLocomotion);

                // Update the inventory.
                var inventory = characterLocomotion.GetComponent <Inventory.Inventory>();
                var loadout   = new List <Inventory.ItemDefinitionAmount>(inventory.DefaultLoadout);
                for (int i = loadout.Count - 1; i > -1; --i)
                {
                    if (loadout[i] == null)
                    {
                        loadout.RemoveAt(i);
                    }
                }
                inventory.DefaultLoadout = loadout.ToArray();
                InspectorUtility.SetDirty(inventory);

                var itemSetManager = characterLocomotion.GetComponent <Inventory.ItemSetManager>();
                if (itemSetManager != null)
                {
                    var categoryItemSets = itemSetManager.CategoryItemSets;
                    for (int i = 0; i < categoryItemSets.Length; ++i)
                    {
                        for (int j = categoryItemSets[i].ItemSetList.Count - 1; j > -1; --j)
                        {
                            var nullItemIdentifier = true;
                            for (int k = 0; k < categoryItemSets[i].ItemSetList[j].Slots.Length; ++k)
                            {
                                if (categoryItemSets[i].ItemSetList[j].Slots[k] != null)
                                {
                                    nullItemIdentifier = false;
                                    break;
                                }
                            }
                            if (nullItemIdentifier)
                            {
                                categoryItemSets[i].ItemSetList.RemoveAt(j);
                            }
                        }
                    }
                    ;
                    InspectorUtility.SetDirty(itemSetManager);
                }
            }

#if !THIRD_PERSON_CONTROLLER
            // Set the shadow caster for the first person only objects.
            var shadowCaster = ManagerUtility.FindInvisibleShadowCaster(null);
            if (shadowCaster != null)
            {
                for (int i = 0; i < objectReferences.ShadowCasterObjects.Length; ++i)
                {
                    if (objectReferences.ShadowCasterObjects[i] == null)
                    {
                        continue;
                    }

                    var renderers = objectReferences.ShadowCasterObjects[i].GetComponentsInChildren <Renderer>();
                    for (int j = 0; j < renderers.Length; ++j)
                    {
                        var materials = renderers[j].sharedMaterials;
                        for (int k = 0; k < materials.Length; ++k)
                        {
                            materials[k] = shadowCaster;
                        }
                        renderers[j].sharedMaterials = materials;
                        InspectorUtility.SetDirty(renderers[j]);
                    }
                }
            }
#endif

            var items = objectReferences.GetComponentsInChildren <Items.Item>();
            for (int i = 0; i < items.Length; ++i)
            {
                CheckItem(items[i].gameObject);
            }

            // Ensure all of the states point to a preset
            StateBehavior[] stateBehaviors;
            if (fromScene)
            {
                stateBehaviors = GameObject.FindObjectsOfType <StateBehavior>();
            }
            else
            {
                stateBehaviors = objectReferences.GetComponentsInChildren <StateBehavior>(true);
            }
            if (stateBehaviors != null)
            {
                for (int i = 0; i < stateBehaviors.Length; ++i)
                {
                    stateBehaviors[i].States = RemoveUnusedStates(stateBehaviors[i].States);
                    InspectorUtility.SetDirty(stateBehaviors[i]);
                }
            }
#endif
            // Some doors should be locked.
#if !FIRST_PERSON_CONTROLLER
            LockDoors(objectReferences.FirstPersonDoors);
#endif
#if !THIRD_PERSON_CONTROLLER
            LockDoors(objectReferences.ThirdPersonDoors);
#endif

            for (int i = 0; i < objectReferences.NestedReferences.Length; ++i)
            {
                GameObject nestedRoot   = null;
                var        nestedObject = objectReferences.NestedReferences[i];
                if (PrefabUtility.IsPartOfPrefabAsset(nestedObject))
                {
                    nestedRoot   = PrefabUtility.LoadPrefabContents(AssetDatabase.GetAssetPath(objectReferences.NestedReferences[i]));
                    nestedObject = nestedRoot.GetComponent <ObjectReferences>();
                }
                ProcessObjectReferences(nestedObject, false);
                if (nestedRoot != null)
                {
                    PrefabUtility.SaveAsPrefabAsset(nestedRoot, AssetDatabase.GetAssetPath(objectReferences.NestedReferences[i]));
                    PrefabUtility.UnloadPrefabContents(nestedRoot);
                }
            }

            UnpackPrefab(objectReferences);
            Object.DestroyImmediate(objectReferences, true);
        }
Пример #6
0
        /// <summary>
        /// Sets up the character to be able to work with pun.
        /// </summary>
        private void SetupCharacter()
        {
            if (m_Object == null)
            {
                return;
            }

            // Remove the single player variants of the necessary components.
            var animatorMonitor = m_Object.GetComponent <AnimatorMonitor>();

            if (animatorMonitor != null)
            {
                GameObject.DestroyImmediate(animatorMonitor, true);
            }
            var characterLocomotionHandler = m_Object.GetComponent <UltimateCharacterLocomotionHandler>();

            if (characterLocomotionHandler != null)
            {
                GameObject.DestroyImmediate(characterLocomotionHandler, true);
                InspectorUtility.AddComponent <Multiplayer.Character.NetworkCharacterLocomotionHandler>(m_Object);
            }

            // The PhotonView will keep the character in sync.
            var photonView = InspectorUtility.AddComponent <PhotonView>(m_Object);

            if (photonView.ObservedComponents == null)
            {
                photonView.ObservedComponents = new System.Collections.Generic.List <Component>();
            }
            photonView.Synchronization = ViewSynchronization.UnreliableOnChange;

            // Add the pun variants.
            var punTransformMonitor = InspectorUtility.AddComponent <Character.PunCharacterTransformMonitor>(m_Object);
            var punAnimatorMonitor  = InspectorUtility.AddComponent <Character.PunAnimatorMonitor>(m_Object);
            var punLookSource       = InspectorUtility.AddComponent <Character.PunLookSource>(m_Object);

            if (!photonView.ObservedComponents.Contains(punTransformMonitor))
            {
                photonView.ObservedComponents.Add(punTransformMonitor);
            }
            if (!photonView.ObservedComponents.Contains(punAnimatorMonitor))
            {
                photonView.ObservedComponents.Add(punAnimatorMonitor);
            }
            if (!photonView.ObservedComponents.Contains(punLookSource))
            {
                photonView.ObservedComponents.Add(punLookSource);
            }

            // Add the independent pun components.
            InspectorUtility.AddComponent <Character.PunCharacter>(m_Object);
            InspectorUtility.AddComponent <PunNetworkInfo>(m_Object);

            // Certain components may be necessary if their single player components is added to the character.
            if (m_Object.GetComponent <AttributeManager>() != null)
            {
                InspectorUtility.AddComponent <Traits.PunAttributeMonitor>(m_Object);
            }
            if (m_Object.GetComponent <Health>() != null)
            {
                InspectorUtility.AddComponent <Traits.PunHealthMonitor>(m_Object);
            }
            if (m_Object.GetComponent <Respawner>() != null)
            {
                InspectorUtility.AddComponent <Traits.PunRespawnerMonitor>(m_Object);
            }
            if (m_Object.GetComponent <Destructible>() != null)
            {
                InspectorUtility.AddComponent <Objects.PunDestructibleMonitor>(m_Object);
            }

            // The RemotePlayerPerspectiveMonitor will switch out the first person materials if the third person Perspective Monitor doesn't exist.
#if THIRD_PERSON_CONTROLLER
            var addRemotePlayerPerspectiveMonitor = m_Object.GetComponent <ThirdPersonController.Character.PerspectiveMonitor>() != null;
#else
            var addRemotePlayerPerspectiveMonitor = true;
#endif
            var invisibleShadowCastor = ManagerUtility.FindInvisibleShadowCaster(m_MainManagerWindow);
            if (addRemotePlayerPerspectiveMonitor)
            {
                var remotePlayerPerspectiveMonitor = InspectorUtility.AddComponent <Multiplayer.Character.RemotePlayerPerspectiveMonitor>(m_Object);
                if (remotePlayerPerspectiveMonitor.InvisibleMaterial == null)
                {
                    remotePlayerPerspectiveMonitor.InvisibleMaterial = invisibleShadowCastor;
                }
            }

            // Any invisible shadow castor materials should be swapped out for a default material.
            var renderers            = m_Object.GetComponentsInChildren <Renderer>(true);
            var updatedMaterialCount = 0;
            var defaultShader        = Shader.Find("Standard");
            for (int i = 0; i < renderers.Length; ++i)
            {
                var materials = renderers[i].sharedMaterials;
                for (int j = 0; j < materials.Length; ++j)
                {
                    if (materials[j] == invisibleShadowCastor)
                    {
                        materials[j] = new Material(defaultShader);
                        updatedMaterialCount++;
                    }
                }
                renderers[i].sharedMaterials = materials;
            }
            if (updatedMaterialCount > 0)
            {
                Debug.Log("Updated " + updatedMaterialCount + " invisible shadow castor materials. Ensure the correct material has been assigned before continuing.");
            }

            // Add the ObjectInspector to any character or ragdoll colliders. This will allow the collider GameObjects to be identifiable over the network.
            var maxID = -1;
            var existingIdentifiers = m_Object.GetComponentsInChildren <ObjectIdentifier>(true);
            for (int i = 0; i < existingIdentifiers.Length; ++i)
            {
                var collider = existingIdentifiers[i].GetComponent <Collider>();
                if (collider != null)
                {
                    // The collider may be used for a ragdoll. Ragdoll colliders should not contribute to the max id.
                    if (!collider.isTrigger &&
                        (collider.gameObject.layer == LayerManager.Character ||
                         (collider.gameObject.layer == LayerManager.SubCharacter && collider.GetComponent <Rigidbody>() != null)))
                    {
                        continue;
                    }
                }

                if (existingIdentifiers[i].ID > maxID)
                {
                    maxID = existingIdentifiers[i].ID;
                }
            }

            // The max available ID has been determined. Add the ObjectIdentifier.
            var colliders = m_Object.GetComponentsInChildren <Collider>(true);
            var IDOffset  = 1;
            for (int i = 0; i < colliders.Length; ++i)
            {
                if (colliders[i].isTrigger ||
                    (colliders[i].gameObject.layer != LayerManager.Character &&
                     (colliders[i].gameObject.layer != LayerManager.SubCharacter || colliders[i].GetComponent <Rigidbody>() == null)))
                {
                    continue;
                }

                var objectIdentifier = InspectorUtility.AddComponent <ObjectIdentifier>(colliders[i].gameObject);
                objectIdentifier.ID = maxID + IDOffset;
                IDOffset++;
            }

            InspectorUtility.SetDirty(m_Object);
        }