public ShooterConfigurations Clone()
        {
            ShooterConfigurations newConfigs = ScriptableObject.CreateInstance <ShooterConfigurations>();

            newConfigs.configs = new Configuration[this.configs.Length];
            for (int i = 0; i < newConfigs.configs.Length; ++i)
            {
                newConfigs.configs[i] = this.configs[i];
            }
            return(newConfigs);
        }
Exemplo n.º 2
0
        void Awake()
        {
            driver   = GetComponent <Driver>();
            scanner  = GetComponentInChildren <Scanner>();
            turner   = GetComponent <Turner>();
            health   = GetComponent <Health>();
            shooters = GetComponents <Shooter>();

            shooterConfigs = shooterConfigsTemplate.Clone();

            for (int si = 0; si < shooterConfigs.Length; ++si)
            {
                ShooterConfigurations.Configuration config = shooterConfigs[si];
                shooters[si].Init(hardpoints[config.hardpointNum], config.weapon);
            }

            vm = new VirtualMachine(this);

            if (code == null)
            {
                Debug.LogWarning("No code provided. Using fallback program.");
                vm.Program = FALLBACK_PROGRAM;
            }
            else
            {
                Program program = Assembler.Assemble(code.text);
                if (program == null)
                {
                    Debug.LogWarning("Assembly failed. Using fallback program.");
                    vm.Program = FALLBACK_PROGRAM;
                }
                else
                {
                    program.name = AssetDatabase.GetAssetPath(code);
                    // TODO: This is a temporary autosave solution; should be redone when editor is put into own menu
                    program.OnChange += () =>
                    {
                        string       progText = Disassembler.Disassemble(vm.Program);
                        StreamWriter progFile = File.CreateText(vm.Program.name);
                        progFile.Write(progText);
                        progFile.Close();
                    };
                    Debug.Log(program.name);
                    vm.Program = program;
                }
            }



            health.OnDisable += HandleDisabled;

            clockTimer = clockInterval;
        }