예제 #1
0
        public void InitializeModuleImporting(string excludeModuleName)
        {
            excludeIndex     = -1;
            modulesInProject = AssetTools.FindAssetsByType <Module>(false, null);

            unityPackagePaths = ProjectTools.GetFilesInDirectory(ModuleWorkFlow.defaultTargetExportDirectory, ProjectTools.packageExtension, out unityPackageNames);


            int l = unityPackagePaths.Length;

            importWarnings = "";

            for (int i = 0; i < l; i++)
            {
                string unVersionedName;
                int    unimportedVersion = ModuleWorkFlow.VersionFromFilePath(unityPackageNames[i], out unVersionedName);

                if (unVersionedName != null)
                {
                    unityPackageNames[i] = unVersionedName;
                }

                if (unityPackageNames[i] == excludeModuleName)
                {
                    excludeIndex = i;
                }


                // check for modules alraedy imported...
                for (int j = 0; j < modulesInProject.Count; j++)
                {
                    Module importedModule = modulesInProject[j];

                    // if package in project already
                    if (unityPackageNames[i] == importedModule.moduleName)
                    {
                        // check if our package version is higher than our already imported version
                        if (unimportedVersion > importedModule.currentVersion)
                        {
                            importWarnings += "\n" + unityPackageNames[i] + " Upgrade available! Version: " + unimportedVersion + ", Current: " + importedModule.currentVersion;

                            // mark as already imported but updateable
                            unityPackageNames[i] = "[...] " + unityPackageNames[i];
                        }
                        else
                        {
                            // mark as already imported
                            unityPackageNames[i] = "[ X ] " + unityPackageNames[i];
                        }
                        break;
                    }
                }
                // add version to name as readable
                unityPackageNames[i] = unityPackageNames[i] + " [v" + unimportedVersion + "]";
            }
        }
예제 #2
0
        public static void RefreshScenesList()
        {
            InitializationScenes instance = InitializationScenes.instance;

            // dont update when in play mode or if our game settings object is missing
            if (Application.isPlaying || instance == null)
            {
                return;
            }

            // update the array of all game settings objects in the project
            SceneAsset[] allScenesInProject = AssetTools.FindAssetsByType <SceneAsset>(logToConsole: false).ToArray();

            SceneAsset        mainScene            = null;
            List <SceneAsset> initializationScenes = new List <SceneAsset>();


            for (int i = 0; i < allScenesInProject.Length; i++)
            {
                if (allScenesInProject[i].name == InitializationScenes.mainInitializationScene)
                {
                    mainScene = allScenesInProject[i];
                    continue;
                }
                if (allScenesInProject[i].name.Contains(InitializationScenes.initializationSceneKey))
                {
                    initializationScenes.Add(allScenesInProject[i]);
                }
            }

            if (mainScene == null)
            {
                Debug.LogError("No Main Initialization scene found named: " + InitializationScenes.mainInitializationScene);
            }
            else
            {
                instance.mainInitializationScenePath = AssetDatabase.GetAssetPath(mainScene);
            }

            int c = initializationScenes.Count;

            instance.initializationSceneNames = new string[c];
            instance.initializationScenePaths = new string[c];

            for (int i = 0; i < c; i++)
            {
                string path = AssetDatabase.GetAssetPath(initializationScenes[i]);
                instance.initializationScenePaths[i] = path;
                instance.initializationSceneNames[i] = Path.GetFileNameWithoutExtension(path);
            }

            AddScenesToBuildSettings(instance);

            EditorUtility.SetDirty(instance);
        }
예제 #3
0
        public bool OnGUI()
        {
            bool reInitialize = false;

            EditorGUILayout.HelpBox(projectSpecifier != null ? string.Format(moduleProjectSpecifierHelp, projectSpecifierModuleName) : noModuleProjectSpecifierHelp, MessageType.Info);
            GUITools.Space();

            if (projectSpecifier != null)
            {
                EditorGUILayout.LabelField("Current Module:", GUITools.boldLabel);
                EditorGUILayout.LabelField(projectSpecifierModuleName);

                if (!string.IsNullOrEmpty(exportWarnings))
                {
                    EditorGUILayout.HelpBox(exportWarnings, MessageType.Warning);
                    GUITools.Space();
                }

                GUITools.Space();

                // show export options
                EditorGUILayout.LabelField("Exporting:", GUITools.boldLabel);
                EditorGUILayout.BeginHorizontal();
                if (GUILayout.Button("Export"))
                {
                    if (DoExport(false))
                    {
                        reInitialize = true;
                    }
                }
                if (GUILayout.Button("Export And Upgrade"))
                {
                    if (DoExport(true))
                    {
                        reInitialize = true;
                    }
                }
                EditorGUILayout.EndHorizontal();
            }
            else
            {
                // create a new module project specifier
                if (GUILayout.Button("Create Module Project Specifier"))
                {
                    ModuleProjectSpecifier specifier = AssetTools.CreateScriptableObject <ModuleProjectSpecifier>(defaultSpecifierPath);
                    Selection.activeObject = specifier;
                    EditorGUIUtility.PingObject(specifier);
                    Debug.Log("Created Module Project Specifier at: " + defaultSpecifierPath);
                    reInitialize = true;
                }
            }
            return(reInitialize);
        }
예제 #4
0
        public static void RefreshGameSettingsList()
        {
    #if UNITY_EDITOR
            // dont update when in play mode or if our game settings object is missing
            if (Application.isPlaying || GameSettings.settings == null)
            {
                return;
            }

            // update the array of all game settings objects in the project
            GameSettings.settings = AssetTools.FindAssetsByType <GameSettingsObject>(log: false, null).ToArray();
            EditorUtility.SetDirty(GameSettings.gameSettings);
    #endif
        }
예제 #5
0
        public static void RefreshScenesList()
        {
            GameManagerSettings settings = GameManagerSettings.instance;

            // dont update when in play mode or if our game settings object is missing
            if (Application.isPlaying || settings == null)
            {
                return;
            }

            // update the array of all game settings objects in the project
            SceneAsset[] allScenesInProject = AssetTools.FindAssetsByType <SceneAsset>(log: false, null).ToArray();

            SceneAsset        mainScene  = null;
            List <SceneAsset> initScenes = new List <SceneAsset>();
            List <SceneAsset> mmScenes   = new List <SceneAsset>();

            for (int i = 0; i < allScenesInProject.Length; i++)
            {
                if (allScenesInProject[i].name == GameManager.mainMenuScene)
                {
                    mainScene = allScenesInProject[i];
                    continue;
                }
                if (allScenesInProject[i].name.StartsWith(initSceneKey))
                {
                    initScenes.Add(allScenesInProject[i]);
                    continue;
                }
                if (allScenesInProject[i].name.StartsWith(mmSceneKey))
                {
                    mmScenes.Add(allScenesInProject[i]);
                    continue;
                }
            }

            if (mainScene == null)
            {
                Debug.LogError("No Main Menu scene found named: " + GameManager.mainMenuScene);
            }
            else
            {
                settings.mainMenuScenePath = AssetDatabase.GetAssetPath(mainScene);
            }

            StoreSceneNames(initScenes, ref settings.initSceneNames);
            StoreSceneNames(mmScenes, ref settings.mmSceneNames);
            EditorUtility.SetDirty(settings);
        }
예제 #6
0
        private void Setup_Refresh(string findValue = "")
        {
            // Load all images from the resource file
            _resourceText = comboBox_Resources.Text;
            var resourceFile = _resourceText.zEnum_To_EnumValue <enBlueprintUIAssets>(); // Get the BlueprintUIAssets enumeral

            imageList1.zFromResourceFile(resourceFile, findValue: findValue);            // Load the resources into imagelist
            if (imageList1.Images.Count == 0)
            {
                toolStripStatusLabel1.Text = "No imagers were found.";
            }
            // Show all images in the listview control
            AssetTools.zListView_FromImageList(listView1, imageList1, View_Get());
            toolStripStatusLabel1.Text = $"Image set '{_resourceText}' loaded.";
        }
예제 #7
0
        public GenericGamepadProfile CreateNewGamepadProfile(string name)
        {
            string dir  = InputManager.fullResourcesDirectory + GamepadHandler.gamepadProfilesResourcesDirectory;
            string path = dir + "/" + name + ".asset";

            int x = 0;

            while (System.IO.File.Exists(path))
            {
                path = dir + "/" + name + x.ToString() + ".asset";
                x++;
            }

            GenericGamepadProfile profile = AssetTools.CreateScriptableObject <GenericGamepadProfile>(path, true);

            NewProfile(profile);

            return(profile);
        }
        public static void RefreshPerksList()
        {
            if (Application.isPlaying)
            {
                return;
            }

            PerksCollection instance = PerksCollection.instance;

            // dont update when in play mode or if our game settings object is missing
            if (instance == null)
            {
                return;
            }

            // update the array of all game settings objects in the project
            Perk[] allScenesInProject = AssetTools.FindAssetsByType <Perk>(log: false, null).ToArray();

            instance.allPerks = allScenesInProject;

            for (int i = 0; i < allScenesInProject.Length; i++)
            {
                for (int j = i + 1; j < allScenesInProject.Length; i++)
                {
                    if (allScenesInProject[i].name == allScenesInProject[j].name)
                    {
                        Debug.LogError("Perks with duplicate names: " + allScenesInProject[i].name);
                    }
                }
            }
            for (int i = 0; i < allScenesInProject.Length; i++)
            {
                for (int j = i + 1; j < allScenesInProject.Length; i++)
                {
                    if (allScenesInProject[i].displayName == allScenesInProject[j].displayName)
                    {
                        Debug.LogError("Perks with duplicate display names: " + allScenesInProject[i].displayName);
                    }
                }
            }
            EditorUtility.SetDirty(instance);
        }
예제 #9
0
        /*
         *  check and see if this project is a module project
         */
        public void InitializeModuleExporting()
        {
            projectSpecifier = null;
            exportWarnings   = "";

            List <ModuleProjectSpecifier> specifiers = AssetTools.FindAssetsByType <ModuleProjectSpecifier>(false, null);

            if (specifiers.Count == 0)
            {
                return;
            }

            projectSpecifier = specifiers[0];

            // show warning if we have more than one in the project...
            if (specifiers.Count > 1)
            {
                exportWarnings = "Found more than one ModuleProjectSpecifier in the project, using the first one located at path: " + AssetDatabase.GetAssetPath(projectSpecifier);
                Debug.LogWarning(exportWarnings);
            }
        }
예제 #10
0
    public static void CreateHighResolutionGeometry(GameObject asset)
    {
        var paths    = AssetTools.FindAssetPaths(asset);
        var original = AssetDatabase.LoadAssetAtPath(paths.file + ".obj", typeof(Mesh)) as Mesh;

        var deformable = AssetDatabase.LoadAssetAtPath(paths.file + "DeformableMesh.asset", typeof(Mesh)) as Mesh;

        if (deformable == null)
        {
            deformable = new Mesh();
            AssetDatabase.CreateAsset(deformable, paths.file + "DeformableMesh.asset");
        }

        EdgeMesh edgemesh = new EdgeMesh();

        edgemesh.Build(original);
        edgemesh.RefineMesh(0.25f);
        edgemesh.BakeMesh(deformable);

        AssetDatabase.SaveAssets();

        asset.GetComponentInChildren <MeshFilter>().sharedMesh = deformable;
    }
예제 #11
0
 public static void GenerateColliders(GameObject gameobject)
 {
     var meshimporter = AssetImporter.GetAtPath(AssetTools.FindAssetPaths(gameobject).assetpath) as ModelImporter;
 }
    public static RuntimeAnimatorController Create(SmwCharacterGenerics smwCharacterGenerics, SmwCharacter smwCharacter, Teams teamId)
    {
        string charName = smwCharacter.charName;

        if (charName == "")
        {
            Debug.LogError("smwCharacter hat keinen namen gesetzt!");
            charName = "unnamedChar";
        }
        Debug.Log("CharacterAnimator" + " Create () " + charName);

        string createdCharacterFolderPath = "Animations/Characters/AutoGenerated/" + charName + "_" + teamId;

        if (!AssetTools.TryCreateFolderWithAssetDatabase(createdCharacterFolderPath, out createdCharacterFolderPath))
        {
            Debug.LogError("Ordner existiert/existerieren nicht und kann/können nicht angelegt werden!\n" + createdCharacterFolderPath);
            return(null);
        }

        /**
         *          AssetDatabase :	All paths are relative to the project folder => paths always = "Assets/..../..." //TODO last folder no SLASH / !!!
         **/


        //		string assetCreatedCharacterFolderPath = "Assets/" + createdCharacterFolderPath;
        AnimatorController controller = AnimatorController.CreateAnimatorControllerAtPath(createdCharacterFolderPath + "/" + charName + "_" + teamId + "_scripted_AnimatorController.controller");

        AddAnimatorControllerParameter(controller);

        #region Layer 0 State Machine

        // Layer 0 State Machine
        AnimatorStateMachine rootStateMachine = controller.layers[0].stateMachine;

        Vector3 anyStatePos = rootStateMachine.anyStatePosition;
        //Vector3 entryStatePos = rootStateMachine.entryPosition;
        Vector3 refStatePos = anyStatePos;
        Vector3 tempStatePos;

        tempStatePos    = anyStatePos;
        tempStatePos.x += 200;
        rootStateMachine.anyStatePosition = tempStatePos;

        /*          Add states           */

        tempStatePos.x = refStatePos.x + 200;
        tempStatePos.y = refStatePos.y - 200;
        AnimatorState idleState = rootStateMachine.AddState(HashID.s_Idle, tempStatePos);
        //		idleState.motion = idleAnim;

        tempStatePos.x = refStatePos.x + 200;
        tempStatePos.y = refStatePos.y - 100;
        AnimatorState jumpState = rootStateMachine.AddState(HashID.s_JumpAndFall, tempStatePos);
        //		jumpState.motion = jumpAnim;

        tempStatePos.x = refStatePos.x + 200;
        tempStatePos.y = refStatePos.y - 300;
        AnimatorState runState = rootStateMachine.AddState(HashID.s_Run, tempStatePos);
        //		runState.motion = runAnim;

        tempStatePos.x = refStatePos.x + 200;
        tempStatePos.y = refStatePos.y - 400;
        AnimatorState skidState = rootStateMachine.AddState(HashID.s_ChangeRunDirection, tempStatePos);
        //		skidState.motion = changeRunDirectionAnim;

        tempStatePos.x = refStatePos.x + 600;
        tempStatePos.y = refStatePos.y;
        AnimatorState hittedState = rootStateMachine.AddState(HashID.s_Generic_Hitted, tempStatePos);
        //		hittedState.motion = idleAnim;

        tempStatePos.x = refStatePos.x + 750;
        tempStatePos.y = refStatePos.y - 100;
        AnimatorState headJumpedState = rootStateMachine.AddState(HashID.s_HeadJumped, tempStatePos);
        //		headJumpedState.motion = headJumpedAnim;

        tempStatePos.x = refStatePos.x + 450;
        tempStatePos.y = refStatePos.y - 100;
        AnimatorState gameOverState = rootStateMachine.AddState(HashID.s_GameOver, tempStatePos);
        //		gameOverState.motion = headJumpedAnim;

        tempStatePos.x = refStatePos.x + 600;
        tempStatePos.y = refStatePos.y - 200;
        AnimatorState deadState = rootStateMachine.AddState(HashID.s_Dead, tempStatePos);
        //		deadState.motion = headJumpedAnim;

        tempStatePos.x = refStatePos.x + 750;
        tempStatePos.y = refStatePos.y - 300;
        AnimatorState spawnState = rootStateMachine.AddState(HashID.s_Generic_Spawn, tempStatePos);
        spawnState.AddStateMachineBehaviour(typeof(SpawnStateScript));          //TODO reference zu characterScript direct mitgeben???
        //		spawnState.AddStateMachineBehaviour(new SpawnStateScript());

        tempStatePos.x = refStatePos.x + 800;
        tempStatePos.y = refStatePos.y - 400;
        AnimatorState spawnDelayState = rootStateMachine.AddState(HashID.s_Generic_SpawnDelay, tempStatePos);
        spawnDelayState.AddStateMachineBehaviour(typeof(SpawnDelayStateScript));            //TODO reference zu characterScript direct mitgeben???
        //		spawnState.AddStateMachineBehaviour(new SpawnDelayStateScript());

        //		spawnState.motion = headJumpedAnim;

        //		AnimatorState spawnProtectionState = rootStateMachine.AddState(HashID.s_Generic_SpawnProtection);
        //		spawnProtectionState.motion = headJumpedAnim;

        #endregion

        #region Layer 1 State Machine - Overlay Layer

        /**
         * Layer 1 - Overlay Layer
         **/

        // FIX defaultWeight and blendingMode!!!!
        //		// Manual Creating Layer : http://forum.unity3d.com/threads/animatorcontroller-addlayer-doesnt-create-default-animatorstatemachine.307873/#post-2003218
        AnimatorControllerLayer newLayer = new AnimatorControllerLayer();
        newLayer.name                   = HashID.l_overlay;
        newLayer.stateMachine           = new AnimatorStateMachine();
        newLayer.stateMachine.name      = newLayer.name;
        newLayer.stateMachine.hideFlags = HideFlags.HideInHierarchy;
        if (AssetDatabase.GetAssetPath(controller) != "")
        {
            AssetDatabase.AddObjectToAsset(newLayer.stateMachine, AssetDatabase.GetAssetPath(controller));
        }
        //Custom
        newLayer.blendingMode  = AnimatorLayerBlendingMode.Override;
        newLayer.defaultWeight = 1f;
        controller.AddLayer(newLayer);


        // Another Way:
        //Animator anim;
        //anim.SetLayerWeight (layerIndex, weight)

//		// Auto Creating Layer & StateMachine  AddLayer(string)!!!
//		controller.AddLayer(HashID.l_overlay);
//		controller.layers[1].blendingMode = AnimatorLayerBlendingMode.Additive;			// setzt für die zeit die es aktiv ist die variablen und wenn deaktiviert wird variable auf vorherigen wert gesetzt
//		controller.layers[1].defaultWeight = 1f;

        if (controller.layers[1].stateMachine == null)
        {
            Debug.LogError("stateMachine == null");
//			controller.layers[1].stateMachine = new AnimatorStateMachine();
        }


        // Layer 1 State Machine
//		controller.layers[1].blendingMode = AnimatorLayerBlendingMode.Override;			// setzt für die zeit die es aktiv ist die variablen und wenn deaktiviert wird variable auf vorherigen wert gesetzt
//		controller.layers[1].defaultWeight = 1f;
        AnimatorStateMachine overlayStateMachine = controller.layers[1].stateMachine;

        refStatePos    = overlayStateMachine.anyStatePosition;
        tempStatePos.x = refStatePos.x + 200;
        tempStatePos.y = refStatePos.y;
        AnimatorState defaultOverlayState = overlayStateMachine.AddState(HashID.s_l1_Generic_DefaultState, tempStatePos);

        tempStatePos.x = refStatePos.x + 200;
        tempStatePos.y = refStatePos.y - 100;
        AnimatorState invincibleOverlayState = overlayStateMachine.AddState(HashID.s_l1_Generic_Invincible, tempStatePos);

        tempStatePos.x = refStatePos.x + 200;
        tempStatePos.y = refStatePos.y + 100;
        AnimatorState protectionOverlayState = overlayStateMachine.AddState(HashID.s_l1_Generic_Protection, tempStatePos);

        #endregion

        #region Layer 1 State Machine - Overlay Layer Transitions

        AnimatorStateTransition leaveInvincibleEnterDefaultState = invincibleOverlayState.AddTransition(defaultOverlayState);
        //		leaveInvincibleEnterDefaultState.AddCondition(AnimatorConditionMode.If, 0, HashID.p_rageTrigger);
        SetupAnimatorStateTransition(leaveInvincibleEnterDefaultState, 0f, true, 1f, false);

        AnimatorStateTransition leaveProtectionEnterDefaultStateByTime = protectionOverlayState.AddTransition(defaultOverlayState);
        //		leaveInvincibleEnterDefaultState.AddCondition(AnimatorConditionMode.If, 0, HashID.p_rageTrigger);
        SetupAnimatorStateTransition(leaveProtectionEnterDefaultStateByTime, 0f, true, 1f, false);

        AnimatorStateTransition leaveProtectionEnterDefaultStateByTrigger = protectionOverlayState.AddTransition(defaultOverlayState);
        SetupAnimatorStateTransition(leaveProtectionEnterDefaultStateByTrigger, 0f, false, 1f, false);
        leaveProtectionEnterDefaultStateByTrigger.AddCondition(AnimatorConditionMode.If, 0, HashID.p_stopProtectionTrigger);                                    //TODO defaultOverlayState muss kräfte invincible/spawnprotection entfernen??

        // Overlay Layer : AnyState Transitions to InvincibleState
        AnimatorStateTransition enterInvincibleOverlayerState = overlayStateMachine.AddAnyStateTransition(invincibleOverlayState);
        SetupAnimatorStateTransition(enterInvincibleOverlayerState, 0f, false, 1f, false);
        enterInvincibleOverlayerState.AddCondition(AnimatorConditionMode.If, 0, HashID.p_rageTrigger);


        // Overlay Layer : AnyState Transitions to ProtectionState
        AnimatorStateTransition enterProtectionOverlayerState = overlayStateMachine.AddAnyStateTransition(protectionOverlayState);              //TODO rename SpawnProtection to Protection
        SetupAnimatorStateTransition(enterProtectionOverlayerState, 0f, false, 1f, false);
        enterProtectionOverlayerState.AddCondition(AnimatorConditionMode.If, 0, HashID.p_startProtectionTrigger);

        #endregion

        #region Layer 0 State Machine Transitions
        // Layer 0 - Base Layer

        float minHorizontalSpeed = 0.01f;       // setze schwellwert (treshold)

        AnimatorStateTransition leaveIdleEnterRunIfGreater = idleState.AddTransition(runState);
        SetupAnimatorStateTransition(leaveIdleEnterRunIfGreater, 0f, false, 1f, false);
        leaveIdleEnterRunIfGreater.AddCondition(AnimatorConditionMode.Greater, minHorizontalSpeed, HashID.p_hSpeed);

        AnimatorStateTransition leaveIdleEnterRunIfLower = idleState.AddTransition(runState);
        SetupAnimatorStateTransition(leaveIdleEnterRunIfLower, 0f, false, 1f, false);
        leaveIdleEnterRunIfLower.AddCondition(AnimatorConditionMode.Less, -minHorizontalSpeed, HashID.p_hSpeed);

        AnimatorStateTransition leaveRunEnterIdle = runState.AddTransition(idleState);
        leaveRunEnterIdle.AddCondition(AnimatorConditionMode.Greater, -minHorizontalSpeed, HashID.p_hSpeed);
        leaveRunEnterIdle.AddCondition(AnimatorConditionMode.Less, minHorizontalSpeed, HashID.p_hSpeed);
        SetupAnimatorStateTransition(leaveRunEnterIdle, 0f, false, 1f, false);

        AnimatorStateTransition leaveRunEnterJump = runState.AddTransition(jumpState);
        leaveRunEnterJump.AddCondition(AnimatorConditionMode.IfNot, 0, HashID.p_grounded);
        SetupAnimatorStateTransition(leaveRunEnterJump, 0f, false, 1f, false);

        AnimatorStateTransition leaveIdleEnterJump = idleState.AddTransition(jumpState);
        SetupAnimatorStateTransition(leaveIdleEnterJump, 0f, false, 1f, false);
        leaveIdleEnterJump.AddCondition(AnimatorConditionMode.IfNot, 0, HashID.p_grounded);


        AnimatorStateTransition leaveJumpEnterIdle = jumpState.AddTransition(idleState);
        SetupAnimatorStateTransition(leaveJumpEnterIdle, 0f, false, 1f, false);
        leaveJumpEnterIdle.AddCondition(AnimatorConditionMode.If, 0, HashID.p_grounded);

        AnimatorStateTransition leaveRunEnterSkid = runState.AddTransition(skidState);
        SetupAnimatorStateTransition(leaveRunEnterSkid, 0f, false, 1f, false);
        leaveRunEnterSkid.AddCondition(AnimatorConditionMode.If, 0, HashID.p_changeRunDirectionTrigger);

        AnimatorStateTransition leaveSkidEnterRun = skidState.AddTransition(runState);
        SetupAnimatorStateTransition(leaveSkidEnterRun, 0f, true, 1f, false);   //TODO achtung byTime!
        //leaveSkidEnterRun.AddCondition(AnimatorConditionMode.IfNot, 0, HashID.p_changeRunDirectionTrigger);

        // Any State Transistion
        AnimatorStateTransition fallingTransition = rootStateMachine.AddAnyStateTransition(jumpState); //special TODO markt
        SetupAnimatorStateTransition(fallingTransition, 0f, false, 1f, false);
        fallingTransition.AddCondition(AnimatorConditionMode.IfNot, 0, HashID.p_grounded);

        // Any State Transistion
        AnimatorStateTransition hittedTransition = rootStateMachine.AddAnyStateTransition(hittedState); //special TODO markt
        SetupAnimatorStateTransition(hittedTransition, 0f, false, 1f, false);
        hittedTransition.AddCondition(AnimatorConditionMode.If, 0, HashID.p_hitTrigger);

        AnimatorStateTransition leaveHittedEnterHeadJumped = hittedState.AddTransition(headJumpedState);
        SetupAnimatorStateTransition(leaveHittedEnterHeadJumped, 0f, false, 1f, false);
        leaveHittedEnterHeadJumped.AddCondition(AnimatorConditionMode.If, 0, HashID.p_headJumped);              // TODO <-- change to Trigger? p_headJumpedTrigger

        AnimatorStateTransition leaveHittedEnterDie = hittedState.AddTransition(deadState);
        SetupAnimatorStateTransition(leaveHittedEnterDie, 0f, false, 1f, false);
        leaveHittedEnterDie.AddCondition(AnimatorConditionMode.If, 0, HashID.p_dead);           // TODO <-- change to name p_dieTrigger

        AnimatorStateTransition leaveHittedEnterGameOver = hittedState.AddTransition(gameOverState);
        SetupAnimatorStateTransition(leaveHittedEnterGameOver, 0f, false, 1f, false);
        leaveHittedEnterGameOver.AddCondition(AnimatorConditionMode.If, 0, HashID.p_gameOver);          // TODO <-- change to name p_gameOverTrigger

        AnimatorStateTransition leaveHeadJumpedEnterSpawn = headJumpedState.AddTransition(spawnState);
        SetupAnimatorStateTransition(leaveHeadJumpedEnterSpawn, 0f, false, 1f, false);
        leaveHeadJumpedEnterSpawn.AddCondition(AnimatorConditionMode.If, 0, HashID.p_spawn);            // TODO <-- change to name p_spawnTrigger

        AnimatorStateTransition leaveDieEnterSpawn = deadState.AddTransition(spawnState);
        SetupAnimatorStateTransition(leaveDieEnterSpawn, 0f, false, 1f, false);
        leaveDieEnterSpawn.AddCondition(AnimatorConditionMode.If, 0, HashID.p_spawn);           // TODO <-- change to name p_spawnTrigger

        AnimatorStateTransition leaveSpawnEnterIdle = spawnState.AddTransition(idleState);
        SetupAnimatorStateTransition(leaveSpawnEnterIdle, 0f, true, 1f, false);     //TODO achtung byTime!	//TODO <-- Achtung  hasExitTime (nach Animation)
        //leaveSpawnEnterIdle.AddCondition(AnimatorConditionMode.If, 0, HashID.p_spawn);		//TODO add condition to enable controlls & enable gravity & & ...

        #endregion

        // init smwAnimations array

        //		int baseLayerStateCount = 0;
        smwAnimations.Clear();          // BUG FIX!
        smwAnimations.Add(new SMWAnimation(charName + "_" + teamId + "_dynamic_Idle", 24, 1, smwCharacter.GetSprites(teamId, SmwCharacterAnimation.Idle), WrapMode.Loop, idleState));
        smwAnimations.Add(new SMWAnimation(charName + "_" + teamId + "_dynamic_Run", 24, 2, smwCharacter.GetSprites(teamId, SmwCharacterAnimation.Run), WrapMode.Loop, runState));
        smwAnimations.Add(new SMWAnimation(charName + "_" + teamId + "_dynamic_Jump", 24, 1, smwCharacter.GetSprites(teamId, SmwCharacterAnimation.Jump), WrapMode.Loop, jumpState));
        smwAnimations.Add(new SMWAnimation(charName + "_" + teamId + "_dynamic_Skid", 24, 1, smwCharacter.GetSprites(teamId, SmwCharacterAnimation.Skid), WrapMode.Loop, skidState));
        smwAnimations.Add(new SMWAnimation(charName + "_" + teamId + "_dynamic_Die", 24, 1, smwCharacter.GetSprites(teamId, SmwCharacterAnimation.Die), WrapMode.Loop, deadState));
        smwAnimations.Add(new SMWAnimation(charName + "_" + teamId + "_dynamic_HeadJumped", 24, 1, smwCharacter.GetSprites(teamId, SmwCharacterAnimation.HeadJumped), WrapMode.Loop, headJumpedState));


        GenerateAnimationClipAssets(smwAnimations, createdCharacterFolderPath, true);


        //TODO:: add Generic AnimationClips to characterAnimatorController
        spawnState.motion             = smwCharacterGenerics.spawnAnimClip;
        protectionOverlayState.motion = smwCharacterGenerics.protectionAnimClip;
        invincibleOverlayState.motion = smwCharacterGenerics.rageAnimClip;
        //TODO

        //smwCharacter.runtimeAnimatorController = controller;
        smwCharacter.SetRuntimeAnimationController(teamId, controller);
        EditorUtility.SetDirty(smwCharacter);                                           // save ScriptableObject
        return(controller);
    }
    static void GenerateAnimationClipAssets(List <SMWAnimation> smwAnimations, string createdCharacterFolderPath, bool replace)
    {
        for (int i = 0; i < smwAnimations.Count; i++)
        {
            // AnimationClip
            AnimationClip tempAnimClip = new AnimationClip();
#if !UNITY_5
            // Setting it as generic allows you to use the animation clip in the animation controller
            AnimationUtility.SetAnimationType(tempAnimClip, ModelImporterAnimationType.Generic);
#endif
            tempAnimClip.name = smwAnimations[i].name;

            // Frames Per Second //TODO ACHTUNG:
            tempAnimClip.frameRate = smwAnimations[i].framesPerSecond;

            // LOOP
            //			Debug.Log( "before loopTime = " + AnimationUtility.GetAnimationClipSettings(tempAnimClip).loopTime);
            //			AnimationUtility.GetAnimationClipSettings(tempAnimClip).loopTime = true;
            //			Debug.Log( "after loopTime = " + AnimationUtility.GetAnimationClipSettings(tempAnimClip).loopTime);

            // LOOP WORKS
            //			Debug.Log( "before serializedClip loopTime = " + AnimationUtility.GetAnimationClipSettings(tempAnimClip).loopTime);
            SerializedObject      serializedClip = new SerializedObject(tempAnimClip);
            AnimationClipSettings clipSettings   = new AnimationClipSettings(serializedClip.FindProperty("m_AnimationClipSettings"));
            clipSettings.loopTime = true;
            serializedClip.ApplyModifiedProperties();
            //			Debug.Log( "after serializedClip loopTime = " + AnimationUtility.GetAnimationClipSettings(tempAnimClip).loopTime);


            // Wrap Mode (Loop, Once, PingPong....)
            tempAnimClip.wrapMode = smwAnimations[i].wrapMode;
            //tempAnimClip.

            // Setup EditorCurveBinding of Animation Clip
            //			CreateAnimationClip(tempAnimClip, smwAnimations[i].sprites, smwAnimations[i].keyFrames, 1.0f/smwAnimations[i].framesPerSecond);
            CreateAnimationClip(tempAnimClip, smwAnimations[i]);

            // Add AnimationClip to State of StateMachine
            smwAnimations[i].animState.motion = tempAnimClip;

            // In order to insure better interpolation of quaternions, call this function after you are finished setting animation curves.
            tempAnimClip.EnsureQuaternionContinuity();

            if (AssetDatabase.Contains(tempAnimClip))
            {
                Debug.LogError(tempAnimClip.name + " in AssetDatabase bereits enthalten, darf nicht erscheinen");
            }
            else
            {
                //					Debug.Log(tempAnimClip.name + " nicht in AssetDatabase vorhanden, wird jetzt gespeichert.");

                // asset anlegen
                //					Debug.Log("Versuche " + tempAnimClip.name + " in Ordner " + "Assets/"+createdCharacterFolderPath + " zu speicheren");

                string animClipAssetPath = createdCharacterFolderPath + "/" + tempAnimClip.name + ".asset";
                if (!replace)
                {
                    animClipAssetPath = AssetTools.GenerateUniqueAssetPath(animClipAssetPath);
                }

                AssetDatabase.CreateAsset(tempAnimClip, animClipAssetPath);
            }
        }
        AssetDatabase.SaveAssets();
    }
예제 #14
0
        public ActionResult Publish(AssetImages model)
        {
            if (!ModelState.IsValid)
            {
                return(View("Publish", model));
            }
            model.asset.Publisher   = User.Identity.Name;
            model.asset.ReleaseDate = DateTime.Now.ToString();
            if (!model.File.FileName.EndsWith("rar") && !model.File.FileName.EndsWith("zip"))
            {
                return(View("Publish", model));
            }
            string[] formats = new string[] { ".jpg", ".png", ".jpeg" };
            bool     Wrong   = true;

            foreach (var image in model.Files)
            {
                foreach (var item in formats)
                {
                    if (image.FileName.Contains(item))
                    {
                        Wrong = false;
                        break;
                    }
                }
            }
            if (Wrong)
            {
                return(View("Publish", model));
            }

            foreach (var file in model.Files)
            {
                if (file == null)
                {
                    //at least 1 photo per asset
                    return(View(model));
                }
                else if (file.ContentLength > 0)
                {
                    Picture c = new Picture();
                    c.ImageData = new byte[file.ContentLength];
                    file.InputStream.Read(c.ImageData, 0, c.ImageData.Length);

                    _photoContext.AssetsPhotos.Add(c);
                    _photoContext.SaveChanges();
                    if (model.asset.imagesId == null)
                    {
                        model.asset.imagesId = c.Id.ToString();
                    }
                    else
                    {
                        model.asset.imagesId += "," + c.Id.ToString();
                    }
                }
            }

            if (model.File.ContentLength > 0)
            {
                MemoryStream target = new MemoryStream();
                model.File.InputStream.CopyTo(target);
                byte[] data = target.ToArray();
                model.asset.assetZip = data;
            }
            model.asset.Size = model.asset.assetZip.Count() / 1048576f;

            //////
            if (model.asset.Type == "2D")
            {
                Asset2D asset2D = new Asset2D(model.asset);
                _context.Assets2D.Add(asset2D);
            }
            else if (model.asset.Type == "3D")
            {
                Asset3D asset3D = new Asset3D(model.asset);
                _context.Assets3D.Add(asset3D);
            }
            else if (model.asset.Type == "Audio")
            {
                AssetAudio assetAudio = new AssetAudio(model.asset);
                _context.AssetsAudio.Add(assetAudio);
            }
            else if (model.asset.Type == "Tools")
            {
                AssetTools assetTools = new AssetTools(model.asset);
                _context.AssetsTools.Add(assetTools);
            }
            else
            {
                return(HttpNotFound());
            }

            try
            {
                _context.SaveChanges();
            }
            catch (DbEntityValidationException e)
            {
                foreach (var eve in e.EntityValidationErrors)
                {
                    Debug.WriteLine("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:",
                                    eve.Entry.Entity.GetType().Name, eve.Entry.State);
                    foreach (var ve in eve.ValidationErrors)
                    {
                        Debug.WriteLine("- Property: \"{0}\", Error: \"{1}\"",
                                        ve.PropertyName, ve.ErrorMessage);
                    }
                }
                Debug.WriteLine(model.asset.Type);
            }


            AllAssets allAssets = new AllAssets();

            allAssets.assets2D    = _context.Assets2D.ToList();
            allAssets.assets3D    = _context.Assets3D.ToList();
            allAssets.assetsAudio = _context.AssetsAudio.ToList();
            allAssets.assetsTools = _context.AssetsTools.ToList();

            return(RedirectToAction("Index", allAssets));
        }