//---------------------------------------------------------------------------

        #endregion

        //---------------------------------------------------------------------------

        #region Accessors and Mutators

        //---------------------------------------------------------------------------



        //---------------------------------------------------------------------------

        #endregion

        //---------------------------------------------------------------------------

        #region Public Member Functions

        //---------------------------------------------------------------------------

        public override void Init(OCBlockSet blockSet)
        {
            base.Init(blockSet);
            _sideVectors   = ToTexCoords(_side);
            _topVectors    = ToTexCoords(_top);
            _bottomVectors = ToTexCoords(_bottom);
        }
Esempio n. 2
0
    void OnEnable()
    {
        blockSet = (OCBlockSet)target;

//		bool allBlocksNull = true;
//
//		for (int i = 0; i < blockSet.Blocks.Length; i++)
//		{
//			if (blockSet.Blocks[i] != null)
//				allBlocksNull = false;
//		}
//
//		if (allBlocksNull)
//			OCBlockSetImport.Import(blockSet, blockSet.Data);

        Type[]      types = Assembly.GetAssembly(typeof(OCBlock)).GetTypes();
        List <Type> list  = new List <Type>();

        foreach (Type type in types)
        {
            if (type.IsSubclassOf(typeof(OCBlock)))
            {
                list.Add(type);
            }
        }

        blockTypes = list.ToArray();
    }
Esempio n. 3
0
    private static void DrawAtlasesList(OCBlockSet blockSet)
    {
        OCAtlas[] list = blockSet.Atlases;
        GUILayout.BeginVertical(GUI.skin.box, GUILayout.ExpandWidth(true));
        {
            selectedAtlas = BlockEditorUtils.DrawList(selectedAtlas, list);
            EditorGUILayout.Separator();

            GUILayout.BeginHorizontal();
            if (GUILayout.Button("Add"))
            {
                ArrayUtility.Add <OCAtlas>(ref list, new OCAtlas());
                selectedAtlas = list.Length - 1;
                GUI.changed   = true;
            }
            if (GUILayout.Button("Remove") && selectedAtlas != -1)
            {
                Undo.RecordObject(blockSet, "Remove atlas");
                ArrayUtility.RemoveAt <OCAtlas>(ref list, selectedAtlas);
                selectedAtlas = Mathf.Clamp(selectedAtlas, 0, list.Length - 1);
                GUI.changed   = true;
            }
            GUILayout.EndHorizontal();
        }
        GUILayout.EndVertical();
        blockSet.Atlases = list;
    }
Esempio n. 4
0
    public static void DrawBlockEditor(OCBlock block, OCBlockSet blockSet)
    {
        UnityEngine.GUILayout.BeginVertical(UnityEngine.GUI.skin.box);
        {
            string name = EditorGUILayout.TextField("Name", block.GetName());
            block.SetName(FixNameString(name));

            if (block is OCGlassBlock)
            {
                OCGlassBlock           glass    = (OCGlassBlock)block;
                UnityEngine.GameObject interior = (UnityEngine.GameObject)EditorGUILayout.ObjectField("Interior", glass.GetInterior(), typeof(UnityEngine.GameObject), true, null);
                glass.SetInterior(interior);
            }

            int atlas = BlockEditorUtils.Popup("Atlas", block.AtlasID, blockSet.Atlases);
            block.AtlasID = atlas;

            int light = EditorGUILayout.IntField("Light", block.GetLight());
            block.SetLight(light);
        }
        UnityEngine.GUILayout.EndVertical();

        UnityEngine.Texture texture = block.GetTexture();
        if (texture != null)
        {
            FieldInfo field = DrawFacesList(block, texture);
            int       face  = (int)field.GetValue(block);
            DrawFaceEditor(ref face, block.Atlas, ref atlasMatrix);
            field.SetValue(block, face);
        }
    }
	public static void DrawBlockEditor(OCBlock block, OCBlockSet blockSet) {

		GUILayout.BeginVertical(GUI.skin.box);
		{
			string name = EditorGUILayout.TextField("Name", block.GetName());
			block.SetName( FixNameString(name) );
			
			if(block is OCGlassBlock)
			{
				OCGlassBlock glass = (OCGlassBlock)block;
				GameObject interior = (GameObject)EditorGUILayout.ObjectField("Interior", glass.GetInterior(), typeof(GameObject), true, null);
				glass.SetInterior( interior );
			}

			int atlas = EditorGUIUtils.Popup( "Atlas", block.AtlasID, blockSet.Atlases );
			block.AtlasID = atlas;
		
			int light = EditorGUILayout.IntField("Light", block.GetLight());
			block.SetLight(light);
		}
		GUILayout.EndVertical();
		
		Texture texture = block.GetTexture();
		if(texture != null) {
			FieldInfo field = DrawFacesList(block, texture);
			int face = (int)field.GetValue(block);
			DrawFaceEditor(ref face, block.Atlas, ref atlasMatrix);
			field.SetValue(block, face);
		}
	}
Esempio n. 6
0
        //---------------------------------------------------------------------------

        #endregion

        //---------------------------------------------------------------------------

        #region Accessors and Mutators

        //---------------------------------------------------------------------------



        //---------------------------------------------------------------------------

        #endregion

        //---------------------------------------------------------------------------

        #region Public Member Functions

        //---------------------------------------------------------------------------

        public virtual void Init(OCBlockSet blockSet)
        {
            _atlas = blockSet.GetAtlas(_atlasID);
            if (_atlas != null)
            {
                _alpha = _atlas.IsAlpha;
            }
        }
	public static int SelectionGrid(OCBlockSet blockSet, int index, params GUILayoutOption[] options) {
		Container<Vector2> scroll = EditorGUIUtils.GetStateObject<Container<Vector2>>(blockSet.GetHashCode());
		
		scroll.value = GUILayout.BeginScrollView(scroll, options);
		index = SelectionGrid(blockSet.Blocks, index);
		GUILayout.EndScrollView();
		
		return index;
	}
	private static void WriteBlockSet(OCBlockSet blockSet, XmlDocument document) {
		XmlNode blockSetNode = document.CreateElement("OCBlockSet");
		document.AppendChild(blockSetNode);
		
		XmlNode atlasListNode = WriteAtlasList(blockSet.Atlases, document);
		blockSetNode.AppendChild(atlasListNode);
		
		XmlNode blockListNode = WriteBlockList(blockSet.Blocks, document);
		blockSetNode.AppendChild(blockListNode);
	}
Esempio n. 9
0
        public static int SelectionGrid(OCBlockSet blockSet, int index, params GUILayoutOption[] options)
        {
            Container <Vector2> scroll = EditorGUIUtils.GetStateObject <Container <Vector2> >(blockSet.GetHashCode());

            scroll.value = GUILayout.BeginScrollView(scroll, options);
            index        = SelectionGrid(blockSet.Blocks, index);
            GUILayout.EndScrollView();

            return(index);
        }
	//---------------------------------------------------------------------------

	#region Private Member Data

	//---------------------------------------------------------------------------
	

			
	//---------------------------------------------------------------------------

	#endregion

	//---------------------------------------------------------------------------

	#region Accessors and Mutators

	//---------------------------------------------------------------------------
		

			
	//---------------------------------------------------------------------------

	#endregion

	//---------------------------------------------------------------------------

	#region Public Member Functions

	//---------------------------------------------------------------------------

	public static void Import(OCBlockSet blockSet, string xml) {
		if(xml != null && xml.Length > 0) {
			XmlDocument document = new XmlDocument();
			document.LoadXml(xml);
			ReadBlockSet(blockSet, document);
		}
		foreach(BaseBlockSet.OCBlock block in blockSet.Blocks) {
			block.Init(blockSet);
		}
	}
	public static string Export(OCBlockSet blockSet) {
		XmlDocument document = new XmlDocument();
		WriteBlockSet(blockSet, document);
		
		StringWriter writer = new StringWriter(new StringBuilder());
        XmlTextWriter xmlWriter = new XmlTextWriter(writer);
		xmlWriter.Formatting = Formatting.Indented;
		
        document.Save( xmlWriter );
        return writer.ToString();
	}
Esempio n. 12
0
    private void DrawBlockSet(OCBlockSet blockSet)
    {
        GUILayout.BeginVertical(GUI.skin.box);

        int oldSelectedBlock = selectedBlock;

        // Next line pushes the blockSet to BlockSetViewer
        selectedBlock = OpenCog.BlockSetViewer.SelectionGrid(blockSet, selectedBlock, GUILayout.MinHeight(200), GUILayout.MaxHeight(300));
        if (selectedBlock != oldSelectedBlock)
        {
            GUIUtility.keyboardControl = 0;
        }

        EditorGUILayout.Separator();

        GUILayout.BeginHorizontal();
        foreach (Type type in blockTypes)
        {
            string name = type.Name;

            if (name.EndsWith("Block"))
            {
                name = name.Substring(0, name.Length - 5);
            }
            if (GUILayout.Button(name))
            {
                OCBlock newBlock = (OCBlock)CreateInstance(type);
                newBlock.SetName("New " + type.ToString());
                newBlock.Init(blockSet);

                OCBlock[] blocks = blockSet.Blocks;
                ArrayUtility.Add <OCBlock>(ref blocks, newBlock);
                blockSet.Blocks = blocks;
                selectedBlock   = blocks.Length - 1;
                EditorGUIUtility.keyboardControl = 0;
                GUI.changed = true;
            }
        }
        GUILayout.EndHorizontal();

        if (GUILayout.Button("Remove"))
        {
            OCBlock[] blocks = blockSet.Blocks;
            ArrayUtility.RemoveAt <OCBlock>(ref blocks, selectedBlock);
            blockSet.Blocks = blocks;
            selectedBlock   = Mathf.Clamp(selectedBlock, 0, blocks.Length - 1);
            GUI.changed     = true;
        }

        GUILayout.EndVertical();
    }
    private static void WriteBlockSet(OCBlockSet blockSet, XmlDocument document)
    {
        XmlNode blockSetNode = document.CreateElement("OCBlockSet");

        document.AppendChild(blockSetNode);

        XmlNode atlasListNode = WriteAtlasList(blockSet.Atlases, document);

        blockSetNode.AppendChild(atlasListNode);

        XmlNode blockListNode = WriteBlockList(blockSet.Blocks, document);

        blockSetNode.AppendChild(blockListNode);
    }
    public static string Export(OCBlockSet blockSet)
    {
        XmlDocument document = new XmlDocument();

        WriteBlockSet(blockSet, document);

        StringWriter  writer    = new StringWriter(new StringBuilder());
        XmlTextWriter xmlWriter = new XmlTextWriter(writer);

        xmlWriter.Formatting = Formatting.Indented;

        document.Save(xmlWriter);
        return(writer.ToString());
    }
	void OnEnable() {
		blockSet = (OCBlockSet)target;

//		bool allBlocksNull = true;
//
//		for (int i = 0; i < blockSet.Blocks.Length; i++)
//		{
//			if (blockSet.Blocks[i] != null)
//				allBlocksNull = false;
//		}
//
//		if (allBlocksNull)
//			OCBlockSetImport.Import(blockSet, blockSet.Data);

		Type[] types = Assembly.GetAssembly(typeof(OCBlock)).GetTypes();
		List<Type> list = new List<Type>();
		foreach(Type type in types) {
			if(type.IsSubclassOf(typeof(OCBlock))) list.Add(type);
		}

		blockTypes = list.ToArray();
	}
	//---------------------------------------------------------------------------

	#endregion

	//---------------------------------------------------------------------------

	#region Accessors and Mutators

	//---------------------------------------------------------------------------
		

			
	//---------------------------------------------------------------------------

	#endregion

	//---------------------------------------------------------------------------

	#region Public Member Functions

	//---------------------------------------------------------------------------

	public override void Init(OCBlockSet blockSet) {
		base.Init(blockSet);
		_sideVectors = ToTexCoords(_side);
		_topVectors = ToTexCoords(_top);
		_bottomVectors = ToTexCoords(_bottom);
	}
	private void DrawBlockSet(OCBlockSet blockSet) {
		GUILayout.BeginVertical(GUI.skin.box);
		
		int oldSelectedBlock = selectedBlock;

		// Next line pushes the blockSet to BlockSetViewer
		selectedBlock = OpenCog.BlockSetViewer.SelectionGrid(blockSet, selectedBlock, GUILayout.MinHeight(200), GUILayout.MaxHeight(300));
		if(selectedBlock != oldSelectedBlock) GUIUtility.keyboardControl = 0;
		
		EditorGUILayout.Separator();
		
		GUILayout.BeginHorizontal();
		foreach(Type type in blockTypes) {
			string name = type.Name;

			if(name.EndsWith("Block")) name = name.Substring(0, name.Length-5);
			if(GUILayout.Button(name)) {
				OCBlock newBlock = (OCBlock) CreateInstance(type);
				newBlock.SetName("New "+type.ToString());
				newBlock.Init(blockSet);
				
				OCBlock[] blocks = blockSet.Blocks;
				ArrayUtility.Add<OCBlock>(ref blocks, newBlock);
				blockSet.Blocks = blocks;
				selectedBlock = blocks.Length-1;
				EditorGUIUtility.keyboardControl = 0;
				GUI.changed = true;
			}
		}
		GUILayout.EndHorizontal();
		
		if( GUILayout.Button("Remove") ) {
			OCBlock[] blocks = blockSet.Blocks;
			ArrayUtility.RemoveAt<OCBlock>(ref blocks, selectedBlock);
			blockSet.Blocks = blocks;
			selectedBlock = Mathf.Clamp(selectedBlock, 0, blocks.Length-1);
			GUI.changed = true;
		}
		
		GUILayout.EndVertical();
	}
	//---------------------------------------------------------------------------

	#endregion

	//---------------------------------------------------------------------------

	#region Private Member Functions

	//---------------------------------------------------------------------------
	
	private static void ReadBlockSet(OCBlockSet blockSet, XmlDocument document) {
		XmlNode blockSetNode = FindNodeByName(document, "OCBlockSet");

		OCAtlas[] atlases = ReadAtlasList(blockSetNode);
		blockSet.Atlases = atlases;
		
		BlockSet.BaseBlockSet.OCBlock[] blocks = ReadBlockList(blockSetNode);

		//Debug.Log("Are we setting a bunch of null blocks?");

		bool allNull = true;

		for (int i = 0; i < blocks.Length; i++)
		{
			if (blocks[i] != null)
				allNull = false;
		}

		if (allNull)
			Debug.Log("Yep, we're setting a bunch of null blocks!");
		else
			//Debug.Log("Nope, they're ok!");

		blockSet.Blocks = blocks;
	}
	private static void DrawAtlasesList( OCBlockSet blockSet ) {
		OCAtlas[] list = blockSet.Atlases;
		GUILayout.BeginVertical(GUI.skin.box, GUILayout.ExpandWidth(true));
		{
			selectedAtlas = EditorGUIUtils.DrawList(selectedAtlas, list);
			EditorGUILayout.Separator();
		
			GUILayout.BeginHorizontal();
				if(GUILayout.Button("Add")) {
					ArrayUtility.Add<OCAtlas>(ref list, new OCAtlas());
					selectedAtlas = list.Length - 1;
					GUI.changed = true;
				}
				if(GUILayout.Button("Remove") && selectedAtlas != -1) {
					Undo.RegisterUndo(blockSet, "Remove atlas");
					ArrayUtility.RemoveAt<OCAtlas>(ref list, selectedAtlas);
					selectedAtlas = Mathf.Clamp(selectedAtlas, 0, list.Length - 1);
					GUI.changed = true;
				}
			GUILayout.EndHorizontal();
		}
		GUILayout.EndVertical();
		blockSet.Atlases = list;
	}
Esempio n. 20
0
	//---------------------------------------------------------------------------

	#endregion

	//---------------------------------------------------------------------------

	#region Accessors and Mutators

	//---------------------------------------------------------------------------
		

			
	//---------------------------------------------------------------------------

	#endregion

	//---------------------------------------------------------------------------

	#region Public Member Functions

	//---------------------------------------------------------------------------

	public virtual void Init(OCBlockSet blockSet) {
		_atlas = blockSet.GetAtlas(_atlasID);
		if(_atlas != null) _alpha = _atlas.IsAlpha;
	}